]> granicus.if.org Git - transmission/commitdiff
(libT) #5259 'Minor memory leak in tr_torrentDeleteLocalData()' -- fixed.
authorJordan Lee <jordan@transmissionbt.com>
Sun, 27 Jan 2013 06:19:33 +0000 (06:19 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sun, 27 Jan 2013 06:19:33 +0000 (06:19 +0000)
libtransmission/torrent.c

index 02404675f4d0fcec05999b7f0a47f1ad136fb20e..a27cb0f44351835ce820772d8037b5f384f77e88 100644 (file)
@@ -2830,14 +2830,14 @@ deleteLocalData (tr_torrent * tor, tr_fileFunc func)
         if (!tr_is_same_file (top, dir) && strcmp (top, dir)) {
             for (;;) {
                 char * parent = tr_dirname (dir);
-                if (tr_is_same_file (top, parent) || !strcmp (top, parent)) {
-                    if (tr_ptrArrayFindSorted (&folders, dir, vstrcmp) == NULL) {
-                        tr_ptrArrayInsertSorted (&folders, tr_strdup (dir), vstrcmp);
-                    }
-                    break;
-                }
-                tr_free (dir);
+                const bool done_walking = tr_is_same_file (top, parent) || !strcmp (top, parent);
+                if (done_walking && tr_ptrArrayFindSorted (&folders, dir, vstrcmp))
+                  tr_ptrArrayInsertSorted (&folders, dir, vstrcmp); /* folders assumes ownership of dir */
+                else
+                  tr_free (dir);
                 dir = parent;
+                if (done_walking)
+                  break;
             }
         }
         tr_free (dir);