]> granicus.if.org Git - fortune-mod/commitdiff
Fix some memory leaks.
authorShlomi Fish <shlomif@shlomifish.org>
Tue, 16 Jan 2018 09:29:14 +0000 (11:29 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Tue, 16 Jan 2018 09:29:14 +0000 (11:29 +0200)
"valgrind doesn't lie.". See
https://github.com/shlomif/fortune-mod/issues/22#issuecomment-357811116
. Now the valgrind test passes with the new Recode at
https://github.com/rrthomas/Recode .

fortune-mod/fortune/fortune.c
fortune-mod/tests/t/valgrind.t

index b2a7e1ef5b2b91e9bd26f86563ee4028bdab151b..98729177b0596eb6adcc5e276bab959fdc338d2b 100644 (file)
@@ -1680,6 +1680,26 @@ static int max(register int i, register int j)
     return (i >= j ? i : j);
 }
 
+static void free_desc(FILEDESC *ptr)
+{
+    while (ptr)
+    {
+        free_desc(ptr->child);
+        do_free(ptr->datfile);
+        do_free(ptr->posfile);
+        do_free(ptr->name);
+        do_free(ptr->path);
+        if (ptr->inf)
+        {
+            fclose(ptr->inf);
+            ptr->inf = NULL;
+        }
+        FILEDESC *next = ptr->next;
+        free(ptr);
+        ptr = next;
+    }
+}
+
 int main(int ac, char *av[])
 {
     const char *ctype;
@@ -1742,6 +1762,9 @@ int main(int ac, char *av[])
 
     recode_delete_request(request);
     recode_delete_outer(outer);
+
+    /* Free the File_list */
+    free_desc(File_list);
     exit(0);
     /* NOTREACHED */
 }
index e7b976bc5df26908ac189df5d9ddc0a01300b7e7..59912f3e9d3aa2e843ca8071af9ef05f1b3758ac 100644 (file)
@@ -6,8 +6,8 @@ use warnings;
 use Test::More;
 use Test::RunValgrind;
 
-plan skip_all => 'lib-recode has memory leaks';
-plan tests => 1;
+plan skip_all => 'lib-recode has memory leaks';
+plan tests => 1;
 
 # TEST
 Test::RunValgrind->new({})->run(