]> granicus.if.org Git - fortune-mod/commitdiff
Fix some memory leaks+skipped valgrind test.
authorShlomi Fish <shlomif@shlomifish.org>
Fri, 22 Apr 2016 12:13:36 +0000 (15:13 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Fri, 22 Apr 2016 12:13:36 +0000 (15:13 +0300)
We need to skip it because librecode has memory leaks.

fortune-mod/Makefile
fortune-mod/fortune/fortune.c
fortune-mod/tests/t/valgrind.t [new file with mode: 0644]
fortune-mod/tests/trailing-space-and-CRs.pl

index 51afd07557522e800a292c0ea810d0f77393c895..480d60c245e46ee281fb0075299ba63e003199b2 100644 (file)
@@ -112,7 +112,7 @@ fortune-bin:
 fortune-debug:
        cd fortune && $(MAKE) CC='$(CC)' \
                    CFLAGS='$(DEBUGCFLAGS) $(REGEXDEFS) -I../util' \
-                   LDFLAGS='$(DEBUGLDFLAGS)' LIBS='$(REGEXLIBS)'
+                   LDFLAGS='$(DEBUGLDFLAGS)' LIBS='$(REGEXLIBS) $(RECODELIBS)'
 
 util-bin:
        cd util && $(MAKE) CC='$(CC)' CFLAGS='$(CFLAGS)'        \
@@ -187,9 +187,12 @@ datfiles-check: cookies-z
 root-check:
        perl tests/trailing-space-and-CRs.pl
 
+tap-check:
+       prove tests/t/*.t
+
 check-deps: all
 
-check: check-deps datfiles-check root-check
+check: check-deps datfiles-check root-check tap-check
 
 clean:
        for i in $(SUBDIRS) ; do (cd $$i && $(MAKE) clean); done
index 174db6414becce30cd3de910c4526d92bd30fb00..bf9d8e422069ae5d6646ae1a6859b99032783ffb 100644 (file)
@@ -680,6 +680,9 @@ int add_file(int percent, register char *file, char *dir,
 //    fprintf(stderr, "State mal: %s\n", testpath);
     if(stat(testpath, &statbuf) == 0)
         fp->utf8_charset = TRUE;
+
+    free (testpath);
+    testpath = NULL;
 //    fprintf(stderr, "Is utf8?: %i\n", fp->utf8_charset );
 
     fp->parent = parent;
@@ -696,6 +699,8 @@ int add_file(int percent, register char *file, char *dir,
             free(path);
         do_free(fp->datfile);
         do_free(fp->posfile);
+        do_free(fp->name);
+        do_free(fp->path);
         if (fp->fd >= 0) close(fp->fd);
         free(fp);
         return FALSE;
@@ -709,6 +714,8 @@ int add_file(int percent, register char *file, char *dir,
             free(path);
         do_free(fp->datfile);
         do_free(fp->posfile);
+        do_free(fp->name);
+        do_free(fp->path);
         if(fp->fd >= 0) close(fp->fd);
         free(fp);
         return TRUE;
@@ -730,6 +737,12 @@ int add_file(int percent, register char *file, char *dir,
         *head = fp;
     }
 
+    if (was_malloc)
+    {
+        free(path);
+        path = NULL;
+    }
+
     return TRUE;
 }
 
@@ -760,10 +773,13 @@ int add_dir(register FILEDESC * fp)
             continue;
         name = strdup(dirent->d_name);
         if (add_file(NO_PROB, name, fp->path, &fp->child, &tailp, fp))
+        {
             fp->num_children++;
-        else
-            free(name);
+        }
+        free(name);
     }
+    closedir(dir);
+    dir = NULL;
     if (fp->num_children == 0)
     {
         /*
@@ -1642,10 +1658,6 @@ void display(FILEDESC * fp)
             fputs((char *)line, stdout);
     }
     fflush(stdout);
-
-    if(fp->utf8_charset) {
-        recode_delete_request(request);
-    }
 }
 
 /*
@@ -1723,6 +1735,9 @@ int main(int ac, char *av[])
         fortlen();
         sleep((unsigned int) max(Fort_len / CPERS, MINW));
     }
+
+    recode_delete_request(request);
+    recode_delete_outer(outer);
     exit(0);
     /* NOTREACHED */
 }
diff --git a/fortune-mod/tests/t/valgrind.t b/fortune-mod/tests/t/valgrind.t
new file mode 100644 (file)
index 0000000..c8cb453
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use Test::RunValgrind;
+
+plan skip_all => 'lib-recode has memory leaks';
+# TEST
+Test::RunValgrind->new({})->run(
+    {
+        log_fn => './fortune--1.valgrind-log',
+        prog => './fortune/fortune',
+        argv => [qw//],
+        blurb => 'fortune valgrind test',
+    }
+);
index 904abb94f12021616c196a80bdb95b54c790ff94..6cfef2a2c40646a34a6b83cded4b092f2258eb7c 100644 (file)
@@ -31,7 +31,7 @@ while (my $r = $tree->next_obj())
             (
                 $r->basename =~ /\A\..*?\.swp\z/
                     or
-                $r->basename =~ /\.(o|dat)\z/
+                $r->basename =~ /\.(o|dat|valgrind-log)\z/
                     or
                 exists($do_not_check{join '/', @{$r->full_components}})
             )