From 80ee176dccf6954c8cc6493283ddadba42b8f694 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 24 Aug 2017 19:14:10 +0200 Subject: scanner: Fix for memleak due to unclosed file pointer When including a file, it is opened by fopen() and therefore needs to be closed after scanning has finished using fclose(), otherwise valgrind will report a memleak. This patch changes struct input_descriptor to track the opened FILE pointer instead of the file descriptor so the pointer is available for closing in scanner_destroy(). While at it, change erec_print() to work on the open FILE pointer so it doesn't have to call fileno() in beforehand. And as a little bonus, use C99 initializer of the buffer to get rid of the call to memset(). Note that it is necessary to call erec_print_list() prior to destroying the scanner, otherwise it will start manipulating an already freed FILE pointer (and therefore crash the program). Signed-off-by: Phil Sutter --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 3519377b..21bd74aa 100644 --- a/src/main.c +++ b/src/main.c @@ -428,8 +428,8 @@ int main(int argc, char * const *argv) if (nft_run(&nft, nf_sock, scanner, &state, &msgs) != 0) rc = NFT_EXIT_FAILURE; out: - scanner_destroy(scanner); erec_print_list(stderr, &msgs, nft.debug_mask); + scanner_destroy(scanner); xfree(buf); cache_release(&nft.cache); iface_cache_release(); -- cgit v1.2.3