bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpftool: Fix JSON writer resource leak in version command
@ 2025-06-16 13:50 Yuan Chen
  2025-06-16 14:24 ` Quentin Monnet
  0 siblings, 1 reply; 5+ messages in thread
From: Yuan Chen @ 2025-06-16 13:50 UTC (permalink / raw)
  To: qmo, ast; +Cc: bpf, linux-kernel, chenyuan_fl, chenyuan

From: chenyuan <chenyuan@kylinos.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: chenyuan <chenyuan@kylinos.cn>
---
 tools/bpf/bpftool/main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index cd5963cb6058..c8838196a3bd 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -164,6 +164,7 @@ static int do_version(int argc, char **argv)
 		jsonw_end_object(json_wtr);	/* features */
 
 		jsonw_end_object(json_wtr);	/* root object */
+		jsonw_destroy(&json_wtr);
 	} else {
 		unsigned int nb_features = 0;
 
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] bpftool: Fix JSON writer resource leak in version command
@ 2025-06-16 15:27 Yuan Chen
  2025-06-16 15:50 ` Quentin Monnet
  2025-06-16 21:19 ` Andrii Nakryiko
  0 siblings, 2 replies; 5+ messages in thread
From: Yuan Chen @ 2025-06-16 15:27 UTC (permalink / raw)
  To: qmo, ast; +Cc: bpf, linux-kernel, chenyuan_fl, Yuan Chen

From: Yuan Chen <chenyuan@kylinos.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@kylinos.cn>
Suggested-by: Quentin Monnet <qmo@kernel.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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-16 21:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-16 13:50 [PATCH] bpftool: Fix JSON writer resource leak in version command Yuan Chen
2025-06-16 14:24 ` Quentin Monnet
  -- strict thread matches above, loose matches on Subject: below --
2025-06-16 15:27 Yuan Chen
2025-06-16 15:50 ` Quentin Monnet
2025-06-16 21:19 ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).