From: Phil Sutter Date: Thu, 11 Aug 2016 23:33:33 +0000 (+0200) Subject: set: prevent memleak in nftnl_jansson_parse_set_info() X-Git-Tag: libnftnl-1.0.7~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d29f0825c33af8c53a939b7f0e8d5beb2ed48c83;p=thirdparty%2Flibnftnl.git set: prevent memleak in nftnl_jansson_parse_set_info() During list populating, in error case the function returns without freeing the newly allocated 'elem' object, thereby losing any references to it. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- diff --git a/src/set.c b/src/set.c index 5f724585..7a41e8ca 100644 --- a/src/set.c +++ b/src/set.c @@ -610,12 +610,12 @@ static int nftnl_jansson_parse_set_info(struct nftnl_set *s, json_t *tree, return -1; json_elem = json_array_get(array, i); - if (json_elem == NULL) - return -1; - - if (nftnl_jansson_set_elem_parse(elem, - json_elem, err) < 0) + if (json_elem == NULL || + nftnl_jansson_set_elem_parse(elem, + json_elem, err) < 0) { + free(elem); return -1; + } list_add_tail(&elem->head, &s->element_list); }