]> git.ipfire.org Git - thirdparty/nftables.git/commit
scanner: Fix for memleak due to unclosed file pointer
authorPhil Sutter <phil@nwl.cc>
Thu, 24 Aug 2017 17:14:10 +0000 (19:14 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 24 Aug 2017 17:20:29 +0000 (19:20 +0200)
commit80ee176dccf6954c8cc6493283ddadba42b8f694
treea43b67b66a4d0c231ca971c137a134ef0a55ff9e
parenta67af69a32cffbd727a48ea7b1d23ce92f1327ee
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 <phil@nwl.cc>
include/nftables.h
src/erec.c
src/main.c
src/scanner.l