Skip to content

Commit 54b72c7

Browse files
chenyuan0001Kernel Patches Daemon
authored andcommitted
bpftool: Fix JSON writer resource leak in version command
When using `bpftool --version -j/-p`, the JSON writer object created in do_version() was not properly destroyed after use. This caused a memory leak each time the version command was executed with JSON output. Fix: 004b45c (tools: bpftool: provide JSON output for all possible commands) Signed-off-by: Yuan Chen <[email protected]> Suggested-by: Quentin Monnet <[email protected]>
1 parent 13e07b5 commit 54b72c7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/bpf/bpftool/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,12 @@ int main(int argc, char **argv)
533533
if (argc < 0)
534534
usage();
535535

536-
if (version_requested)
537-
return do_version(argc, argv);
536+
if (version_requested) {
537+
ret = do_version(argc, argv);
538+
if (json_output)
539+
jsonw_destroy(&json_wtr);
540+
return ret;
541+
}
538542

539543
ret = cmd_select(commands, argc, argv, do_help);
540544

0 commit comments

Comments
 (0)