Skip to contentSkip to conversation

cli: Make valgrind happy

PATCH In review Phil Sutter 2 participants 4 messages Jun 20, 2023 – Jun 21, 2023 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 cli: Make valgrind happy

Missing call to nft_ctx_free() upsets valgrind enough to suspect possible losses, add them where sensible. This fixes reports with readline-lined builds at least. The same code is shared for libedit though, and there's an obvious spot for linenoise.

---
 src/cli.c | 3 +++
 1 file changed, 3 insertions(+)
src/cli.c +3 -0
index 11fc85abeaa2b..bc7f64ef0b762 100644
@@ -126,6 +126,7 @@ static void cli_complete(char *line)
 	if (line == NULL) {
 		printf("\n");
 		cli_exit();
+		nft_ctx_free(cli_nft);
 		exit(0);
 	}
 
@@ -141,6 +142,7 @@ static void cli_complete(char *line)
 
 	if (!strcmp(line, CMDLINE_QUIT)) {
 		cli_exit();
+		nft_ctx_free(cli_nft);
 		exit(0);
 	}
 
@@ -244,6 +246,7 @@ int cli_init(struct nft_ctx *nft)
 		linenoiseFree(line);
 	}
 	cli_exit();
+	nft_ctx_free(nft);
 	exit(0);
 }
 
Signature · 1 line
2.40.0
#1 lore raw
Quoted 4 lines · Phil Sutter

Missing call to nft_ctx_free() upsets valgrind enough to suspect possible losses, add them where sensible. This fixes reports with readline-lined builds at least. The same code is shared for libedit though, and there's an obvious spot for linenoise.

Maybe call nft_ctx_free() from cli_exit() ?

Quoted 36 lines
---
 src/cli.c | 3 +++
 1 file changed, 3 insertions(+)
src/cli.c +3 -0
index 11fc85abeaa2b..bc7f64ef0b762 100644
@@ -126,6 +126,7 @@ static void cli_complete(char *line)
 	if (line == NULL) {
 		printf("\n");
 		cli_exit();
+		nft_ctx_free(cli_nft);
 		exit(0);
 	}
 
@@ -141,6 +142,7 @@ static void cli_complete(char *line)
 
 	if (!strcmp(line, CMDLINE_QUIT)) {
 		cli_exit();
+		nft_ctx_free(cli_nft);
 		exit(0);
 	}
 
@@ -244,6 +246,7 @@ int cli_init(struct nft_ctx *nft)
 		linenoiseFree(line);
 	}
 	cli_exit();
+	nft_ctx_free(nft);
 	exit(0);
 }
 
Signature · 1 line
2.40.0
author reviewer
#2 lore raw
Quoted 7 lines · Pablo Neira Ayuso
Quoted 4 lines · Phil Sutter

Missing call to nft_ctx_free() upsets valgrind enough to suspect possible losses, add them where sensible. This fixes reports with readline-lined builds at least. The same code is shared for libedit though, and there's an obvious spot for linenoise.

Maybe call nft_ctx_free() from cli_exit() ?

That's doable, but linenoise code does not use the static global cli_nft variable and thus cli_exit() can't access the struct nft_ctx pointer.

At first, I tried to make main() not exit after calling cli_init() so final cleanup takes place. But the different CLI variants are a bit of a mess in that regard: While there are code-paths returning to caller, most don't. I'm tempted to fix that instead. What do you think?

Thanks, Phil

#3 lore raw
Quoted 9 lines · Phil Sutter
Quoted 7 lines · Pablo Neira Ayuso
Quoted 4 lines · Phil Sutter

Missing call to nft_ctx_free() upsets valgrind enough to suspect possible losses, add them where sensible. This fixes reports with readline-lined builds at least. The same code is shared for libedit though, and there's an obvious spot for linenoise.

Maybe call nft_ctx_free() from cli_exit() ?

Quoted 7 lines

That's doable, but linenoise code does not use the static global cli_nft variable and thus cli_exit() can't access the struct nft_ctx pointer.

At first, I tried to make main() not exit after calling cli_init() so final cleanup takes place. But the different CLI variants are a bit of a mess in that regard: While there are code-paths returning to caller, most don't. I'm tempted to fix that instead. What do you think?

That's also fine, go ahead update and test all these cli variants.