From f20466c4bf80fbc9822c1fec644829c2eabecbb7 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Tue, 16 Jan 2018 12:11:03 +0200 Subject: [PATCH] Fix a memleak when using the "-f" flag. --- fortune-mod/fortune/fortune.c | 27 ++++++++++++++------------- fortune-mod/tests/t/valgrind.t | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/fortune-mod/fortune/fortune.c b/fortune-mod/fortune/fortune.c index 9872917..3ec1a91 100644 --- a/fortune-mod/fortune/fortune.c +++ b/fortune-mod/fortune/fortune.c @@ -1742,24 +1742,25 @@ int main(int ac, char *av[]) if (Equal_probs) calc_equal_probs(); print_list(File_list, 0); - exit(0); } - srandom((unsigned int) (time((time_t *) NULL) + getpid())); - do + else { - get_fort(); - } - while ((Short_only && fortlen() > SLEN) || - (Long_only && fortlen() <= SLEN)); + srandom((unsigned int) (time((time_t *) NULL) + getpid())); + do + { + get_fort(); + } + while ((Short_only && fortlen() > SLEN) || + (Long_only && fortlen() <= SLEN)); - display(Fortfile); + display(Fortfile); - if (Wait) - { - fortlen(); - sleep((unsigned int) max(Fort_len / CPERS, MINW)); + if (Wait) + { + fortlen(); + sleep((unsigned int) max(Fort_len / CPERS, MINW)); + } } - recode_delete_request(request); recode_delete_outer(outer); diff --git a/fortune-mod/tests/t/valgrind.t b/fortune-mod/tests/t/valgrind.t index 59912f3..38ea5fc 100644 --- a/fortune-mod/tests/t/valgrind.t +++ b/fortune-mod/tests/t/valgrind.t @@ -7,10 +7,12 @@ use Test::More; use Test::RunValgrind; # plan skip_all => 'lib-recode has memory leaks'; -plan tests => 1; +plan tests => 2; + +my $obj = Test::RunValgrind->new({}); # TEST -Test::RunValgrind->new({})->run( +$obj->run( { log_fn => './fortune--1.valgrind-log', prog => './fortune', @@ -18,3 +20,13 @@ Test::RunValgrind->new({})->run( blurb => 'fortune valgrind test', } ); + +# TEST +$obj->run( + { + log_fn => './fortune--2-dash-f.valgrind-log', + prog => './fortune', + argv => [qw/-f/], + blurb => 'fortune -f valgrind test', + } +); -- 2.40.0