diff options
author | Álvaro Neira Ayuso <alvaroneay@gmail.com> | 2013-08-14 12:19:19 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-08-17 12:49:54 +0200 |
commit | 0334a23918ebb008f81694e855141b8d8f5f72a9 (patch) | |
tree | a49a29e51fe88de8eb3253b4539f9082f7da4f89 /src/table.c | |
parent | 7c24c00fe03318a4b95a0b9cf02257604c954937 (diff) |
json: fixed some leaks in the json parsing function
This patch fixes some leaks in the json parsing function. After this patch,
we use nft_jansson_free_root. This function uses json_decref and it
decrements the reference count and it releases the node if needed.
Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/table.c')
-rw-r--r-- | src/table.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/table.c b/src/table.c index 26bf60d..b51a383 100644 --- a/src/table.c +++ b/src/table.c @@ -269,13 +269,17 @@ err: static int nft_table_json_parse(struct nft_table *t, char *json) { #ifdef JSON_PARSING - json_t *root; + json_t *root, *node; json_error_t error; uint32_t table_flag; const char *str; int family; - root = nft_jansson_get_root(json, "table", &error); + node = nft_jansson_create_root(json, &error); + if (node == NULL) + return -1; + + root = nft_jansson_get_node(node, "table"); if (root == NULL) return -1; @@ -283,10 +287,10 @@ static int nft_table_json_parse(struct nft_table *t, char *json) if (str == NULL) goto err; - nft_table_attr_set_str(t, NFT_TABLE_ATTR_NAME, strdup(str)); + nft_table_attr_set_str(t, NFT_TABLE_ATTR_NAME, str); if (nft_jansson_parse_family(root, &family) != 0) - return -1; + goto err; nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FAMILY, family); @@ -296,10 +300,10 @@ static int nft_table_json_parse(struct nft_table *t, char *json) nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FLAGS, table_flag); - xfree(root); + nft_jansson_free_root(node); return 0; err: - xfree(root); + nft_jansson_free_root(node); return -1; #else errno = EOPNOTSUPP; |