diff mbox series

[v2,1/3] perf header: Fix one memory leakage in process_bpf_btf()

Message ID 20241205084500.823660-2-quic_zhonhan@quicinc.com (mailing list archive)
State Not Applicable
Headers show
Series perf tool: Fix multiple memory leakages | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Zhongqiu Han Dec. 5, 2024, 8:44 a.m. UTC
If __perf_env__insert_btf() returns false due to a duplicate btf node
insertion, the temporary node will leak. Add a check to ensure the memory
is freed if the function returns false.

Fixes: a70a1123174a ("perf bpf: Save BTF information as headers to perf.data")
Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/header.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 3451e542b69a..fbba6ffafec4 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3205,7 +3205,8 @@  static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
 		if (__do_read(ff, node->data, data_size))
 			goto out;
 
-		__perf_env__insert_btf(env, node);
+		if (!__perf_env__insert_btf(env, node))
+			free(node);
 		node = NULL;
 	}