[nft] libnftables: Fix memleak in nft_parse_bison_filename()

Message ID 20181012112255.12807-1-phil@nwl.cc
State Accepted
Delegated to: Pablo Neira
Headers show
Series
  • [nft] libnftables: Fix memleak in nft_parse_bison_filename()
Related show

Commit Message

Phil Sutter Oct. 12, 2018, 11:22 a.m.
Allocated scanner object leaks when returning to caller. For some odd
reason, this was missed by the commit referenced below.

Fixes: bd82e03e15df8 ("libnftables: Move scanner object into struct nft_ctx")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/libnftables.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Pablo Neira Ayuso Oct. 15, 2018, 12:09 p.m. | #1
On Fri, Oct 12, 2018 at 01:22:55PM +0200, Phil Sutter wrote:
> Allocated scanner object leaks when returning to caller. For some odd
> reason, this was missed by the commit referenced below.

Applied, thanks.

Patch

diff --git a/src/libnftables.c b/src/libnftables.c
index 547aa59bf978c..23a262ca46fe3 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -420,15 +420,14 @@  static int nft_parse_bison_filename(struct nft_ctx *nft, const char *filename,
 				    struct list_head *msgs, struct list_head *cmds)
 {
 	struct cmd *cmd;
-	void *scanner;
 	int ret;
 
 	parser_init(nft, nft->state, msgs, cmds);
-	scanner = scanner_init(nft->state);
-	if (scanner_read_file(scanner, filename, &internal_location) < 0)
+	nft->scanner = scanner_init(nft->state);
+	if (scanner_read_file(nft->scanner, filename, &internal_location) < 0)
 		return -1;
 
-	ret = nft_parse(nft, scanner, nft->state);
+	ret = nft_parse(nft, nft->scanner, nft->state);
 	if (ret != 0 || nft->state->nerrs > 0)
 		return -1;