]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bpftool: Fix JSON writer resource leak in version command
authorYuan Chen <chenyuan@kylinos.cn>
Tue, 17 Jun 2025 13:24:42 +0000 (09:24 -0400)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 17 Jun 2025 20:28:26 +0000 (13:28 -0700)
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: 004b45c0e51a (tools: bpftool: provide JSON output for all possible commands)

Suggested-by: Quentin Monnet <qmo@kernel.org>
Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20250617132442.9998-1-chenyuan_fl@163.com
tools/bpf/bpftool/main.c

index cd5963cb6058735dfc6f6778b0fc86d7672e27c8..2b7f2bd3a7dbc7095c5363d44a6bf3bf6f8564fd 100644 (file)
@@ -534,9 +534,9 @@ int main(int argc, char **argv)
                usage();
 
        if (version_requested)
-               return do_version(argc, argv);
-
-       ret = cmd_select(commands, argc, argv, do_help);
+               ret = do_version(argc, argv);
+       else
+               ret = cmd_select(commands, argc, argv, do_help);
 
        if (json_output)
                jsonw_destroy(&json_wtr);