]> granicus.if.org Git - fortune-mod/commitdiff
Fix memleaks with -m flag.
authorShlomi Fish <shlomif@shlomifish.org>
Tue, 16 Jan 2018 10:26:07 +0000 (12:26 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Tue, 16 Jan 2018 10:26:07 +0000 (12:26 +0200)
fortune-mod/fortune/fortune.c
fortune-mod/tests/t/valgrind.t

index 3ec1a917f6621effc1c9270a0600a109e754a805..2c624cd36b6432d455fe6b8ed57191ee63431c67 100644 (file)
@@ -1704,6 +1704,7 @@ int main(int ac, char *av[])
 {
     const char *ctype;
     char *crequest;
+    int exit_code = 0;
 
     env_lang=getenv("LC_ALL");
     if (!env_lang) env_lang=getenv("LC_MESSAGES");
@@ -1733,7 +1734,11 @@ int main(int ac, char *av[])
 
 #ifndef NO_REGEX
     if (Match)
-        exit(find_matches() != 0);
+    {
+        exit_code = (find_matches() != 0);
+        regfree(&Re_pat);
+        goto cleanup;
+    }
 #endif
     init_prob();
     if (Find_files)
@@ -1761,11 +1766,13 @@ int main(int ac, char *av[])
             sleep((unsigned int) max(Fort_len / CPERS, MINW));
         }
     }
+cleanup:
     recode_delete_request(request);
     recode_delete_outer(outer);
 
     /* Free the File_list */
     free_desc(File_list);
-    exit(0);
+    free(Fortbuf);
+    exit(exit_code);
     /* NOTREACHED */
 }
index 38ea5fc22954ba46899719e0dfb6b13791971dea..bd25ad38aa114756bd7663382ac1df541aade566 100644 (file)
@@ -7,7 +7,7 @@ use Test::More;
 use Test::RunValgrind;
 
 # plan skip_all => 'lib-recode has memory leaks';
-plan tests => 2;
+plan tests => 3;
 
 my $obj = Test::RunValgrind->new({});
 
@@ -30,3 +30,13 @@ $obj->run(
         blurb => 'fortune -f valgrind test',
     }
 );
+
+# TEST
+$obj->run(
+    {
+        log_fn => './fortune--3-dash-m.valgrind-log',
+        prog => './fortune',
+        argv => [qw/-m foobarbazINGAMINGATONGALKIYRE/],
+        blurb => 'fortune -m valgrind test',
+    }
+);