diff mbox series

[nft] json: Fix memleak in set_dtype_json()

Message ID 20201008171013.17076-1-phil@nwl.cc
State Accepted
Delegated to: Pablo Neira
Headers show
Series [nft] json: Fix memleak in set_dtype_json() | expand

Commit Message

Phil Sutter Oct. 8, 2020, 5:10 p.m. UTC
Turns out json_string() already dups the input, so the temporary dup
passed to it is lost.

Fixes: e70354f53e9f6 ("libnftables: Implement JSON output support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Pablo Neira Ayuso Oct. 12, 2020, 1:03 p.m. UTC | #1
On Thu, Oct 08, 2020 at 07:10:13PM +0200, Phil Sutter wrote:
> Turns out json_string() already dups the input, so the temporary dup
> passed to it is lost.

LGTM.

> Fixes: e70354f53e9f6 ("libnftables: Implement JSON output support")
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
>  src/json.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/json.c b/src/json.c
> index 121dfb247d967..a8824d3fc05a9 100644
> --- a/src/json.c
> +++ b/src/json.c
> @@ -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))
> -- 
> 2.28.0
>
diff mbox series

Patch

diff --git a/src/json.c b/src/json.c
index 121dfb247d967..a8824d3fc05a9 100644
--- a/src/json.c
+++ b/src/json.c
@@ -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))