cli: Make valgrind happy
Phil Sutter
reviewerPATCH 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
@@ -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
Pablo Neira Ayuso
maintainerQuoted 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
Signed-off-by Phil Sutter <[email protected]>--- src/cli.c | 3 +++ 1 file changed, 3 insertions(+)src/cli.c +3
-0@@ -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
Phil Sutter
reviewerQuoted 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()fromcli_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
Pablo Neira Ayuso
maintainerQuoted 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()fromcli_exit()?
Quoted 7 lines
That's doable, but linenoise code does not use the static global
cli_nftvariable and thuscli_exit()can't access the structnft_ctxpointer.At first, I tried to make
main()not exit after callingcli_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.