From 5799fb118a6c3e050a606329775bddee1eaea444 Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Tue, 23 Oct 2012 14:06:12 +0200 Subject: [PATCH] cfgparser: fix some memory leaks Coverity: CID 739682 (#1 of 2): Resource leak (RESOURCE_LEAK) At (84): Variable "in" going out of scope leaks the storage it points to. CID 739682 (#2 of 2): Resource leak (RESOURCE_LEAK) At (89): Variable "in" going out of scope leaks the storage it points to. Signed-off-by: Ferry Huberts --- src/cfgparser/oparse.y | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cfgparser/oparse.y b/src/cfgparser/oparse.y index cfea5ef6..f5d4e5bb 100644 --- a/src/cfgparser/oparse.y +++ b/src/cfgparser/oparse.y @@ -430,6 +430,13 @@ ifdblock: TOK_INTERFACE_DEFAULTS if (in->cnf == NULL || in->cnfi == NULL) { fprintf(stderr, "Out of memory(ADD DEFIFRULE)\n"); + if (in->cnf) { + free(in->cnf); + } + if (in->cnfi) { + free(in->cnfi); + } + free(in); YYABORT; } @@ -965,6 +972,7 @@ ifnick: TOK_STRING in->cnf = malloc(sizeof(*in->cnf)); if (in->cnf == NULL) { fprintf(stderr, "Out of memory(ADD IFRULE)\n"); + free(in); YYABORT; } memset(in->cnf, 0x00, sizeof(*in->cnf)); @@ -972,6 +980,7 @@ ifnick: TOK_STRING in->cnfi = malloc(sizeof(*in->cnfi)); if (in->cnf == NULL) { fprintf(stderr, "Out of memory(ADD IFRULE)\n"); + free(in); YYABORT; } memset(in->cnfi, 0xFF, sizeof(*in->cnfi));