From: Zhongqiu Han Date: Thu, 5 Dec 2024 08:44:58 +0000 (+0800) Subject: perf header: Fix one memory leakage in process_bpf_btf() X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=875d22980a062521beed7b5df71fb13a1af15d83;p=users%2Fdwmw2%2Flinux.git perf header: Fix one memory leakage in process_bpf_btf() 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: a70a1123174ab592 ("perf bpf: Save BTF information as headers to perf.data") Reviewed-by: Namhyung Kim Signed-off-by: Zhongqiu Han Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Peter Zijlstra Cc: Song Liu Cc: Yicong Yang Link: https://lore.kernel.org/r/20241205084500.823660-2-quic_zhonhan@quicinc.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 3451e542b69a8..fbba6ffafec4a 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; }