]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
set: prevent memleak in nftnl_jansson_parse_set_info()
authorPhil Sutter <psutter@redhat.com>
Thu, 11 Aug 2016 23:33:33 +0000 (01:33 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 11 Aug 2016 23:45:40 +0000 (01:45 +0200)
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 <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/set.c

index 5f7245855db5366e36cd49c709171d208b8cb8c7..7a41e8caeb3c0cc89b89fce86e388c04d29fde55 100644 (file)
--- 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);
                }