[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250616152719.28917-1-chenyuan_fl@163.com>
Date: Mon, 16 Jun 2025 11:27:19 -0400
From: Yuan Chen <chenyuan_fl@....com>
To: qmo@...nel.org,
ast@...nel.org
Cc: bpf@...r.kernel.org,
linux-kernel@...r.kernel.org,
chenyuan_fl@....com,
Yuan Chen <chenyuan@...inos.cn>
Subject: [PATCH] bpftool: Fix JSON writer resource leak in version command
From: Yuan Chen <chenyuan@...inos.cn>
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)
Signed-off-by: Yuan Chen <chenyuan@...inos.cn>
Suggested-by: Quentin Monnet <qmo@...nel.org>
---
tools/bpf/bpftool/main.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index cd5963cb6058..33c68eccd2c3 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -533,8 +533,12 @@ int main(int argc, char **argv)
if (argc < 0)
usage();
- if (version_requested)
- return do_version(argc, argv);
+ if (version_requested) {
+ ret = do_version(argc, argv);
+ if (json_output)
+ jsonw_destroy(&json_wtr);
+ return ret;
+ }
ret = cmd_select(commands, argc, argv, do_help);
--
2.44.0
Powered by blists - more mailing lists