diff options
author | Phil Sutter <phil@nwl.cc> | 2020-07-29 14:21:12 +0200 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2020-07-29 16:55:03 +0200 |
commit | 9608780eee0fbf7055b515ce69cc56c78b96e4bb (patch) | |
tree | 46fba94f0884b1e16cb82d2b65edb8a6afad0110 /src/json.c | |
parent | ba2d0b45e9982ed8764dbeffaf6f4110f308fef8 (diff) |
json: Expect refcount increment by json_array_extend()
This function is apparently not "joining" two arrays but rather copying
all items from the second array to the first, leaving the original
reference in place. Therefore it naturally increments refcounts, which
means if used to join two arrays caller must explicitly decrement the
second array's refcount.
Fixes: e70354f53e9f6 ("libnftables: Implement JSON output support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1568,7 +1568,7 @@ static json_t *table_print_json_full(struct netlink_ctx *ctx, static json_t *do_list_ruleset_json(struct netlink_ctx *ctx, struct cmd *cmd) { unsigned int family = cmd->handle.family; - json_t *root = json_array(); + json_t *root = json_array(), *tmp; struct table *table; list_for_each_entry(table, &ctx->nft->cache.list, list) { @@ -1576,7 +1576,9 @@ static json_t *do_list_ruleset_json(struct netlink_ctx *ctx, struct cmd *cmd) table->handle.family != family) continue; - json_array_extend(root, table_print_json_full(ctx, table)); + tmp = table_print_json_full(ctx, table); + json_array_extend(root, tmp); + json_decref(tmp); } return root; |