From: Shlomi Fish Date: Fri, 22 Apr 2016 12:13:36 +0000 (+0300) Subject: Fix some memory leaks+skipped valgrind test. X-Git-Tag: fortune-mod-1.99.3~35 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f66605df15918526e82ed31f9739c7e6603f7cc5;p=fortune-mod Fix some memory leaks+skipped valgrind test. We need to skip it because librecode has memory leaks. --- diff --git a/fortune-mod/Makefile b/fortune-mod/Makefile index 51afd07..480d60c 100644 --- a/fortune-mod/Makefile +++ b/fortune-mod/Makefile @@ -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 diff --git a/fortune-mod/fortune/fortune.c b/fortune-mod/fortune/fortune.c index 174db64..bf9d8e4 100644 --- a/fortune-mod/fortune/fortune.c +++ b/fortune-mod/fortune/fortune.c @@ -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 index 0000000..c8cb453 --- /dev/null +++ b/fortune-mod/tests/t/valgrind.t @@ -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', + } +); diff --git a/fortune-mod/tests/trailing-space-and-CRs.pl b/fortune-mod/tests/trailing-space-and-CRs.pl index 904abb9..6cfef2a 100644 --- a/fortune-mod/tests/trailing-space-and-CRs.pl +++ b/fortune-mod/tests/trailing-space-and-CRs.pl @@ -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}}) )