From 0334a23918ebb008f81694e855141b8d8f5f72a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Neira=20Ayuso?= Date: Wed, 14 Aug 2013 12:19:19 +0200 Subject: 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 Signed-off-by: Pablo Neira Ayuso --- src/table.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/table.c') 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; -- cgit v1.2.3