Skip to contentSkip to conversation

json: Fix memleak in set_dtype_json()

PATCH In review Phil Sutter 2 participants 2 messages Oct 8, 2020 – Oct 12, 2020 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 json: Fix memleak in set_dtype_json()

Turns out json_string() already dups the input, so the temporary dup passed to it is lost.

Fixes e70354f53e9f6 ("libnftables: Implement JSON output support")
---
 src/json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/json.c +1 -1
index 121dfb247d967..a8824d3fc05a9 100644
@@ -62,7 +62,7 @@ static json_t *set_dtype_json(const struct expr *key)
 
 	tok = strtok(namedup, " .");
 	while (tok) {
-		json_t *jtok = json_string(xstrdup(tok));
+		json_t *jtok = json_string(tok);
 		if (!root)
 			root = jtok;
 		else if (json_is_string(root))
Signature · 1 line
2.28.0
#1 lore raw
Quoted 2 lines · Phil Sutter

Turns out json_string() already dups the input, so the temporary dup passed to it is lost.

LGTM.

Quoted 22 lines
Fixes e70354f53e9f6 ("libnftables: Implement JSON output support")
---
 src/json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/json.c +1 -1
index 121dfb247d967..a8824d3fc05a9 100644
@@ -62,7 +62,7 @@ static json_t *set_dtype_json(const struct expr *key)
 
 	tok = strtok(namedup, " .");
 	while (tok) {
-		json_t *jtok = json_string(xstrdup(tok));
+		json_t *jtok = json_string(tok);
 		if (!root)
 			root = jtok;
 		else if (json_is_string(root))
Signature · 1 line
2.28.0