[PATCH 6.19 012/844] perf symbol-elf: Fix leak of ELF files with GNU debugdata

From: Sasha Levin

Date: Sat Feb 28 2026 - 12:37:16 EST


From: Ian Rogers <irogers@xxxxxxxxxx>

[ Upstream commit 92d65d9c31621befe0a5f7c0bd43bd217613c6b6 ]

The processing of DSO_BINARY_TYPE__GNU_DEBUGDATA in symsrc__init happens
with an open ELF file but the error path only closes the associate fd.

Fix the goto so that the ELF file is also ended and memory released.

Fixes: b10f74308e130527 ("perf symbol: Support .gnu_debugdata for symbols")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
Cc: Aditya Bodkhe <aditya.b1@xxxxxxxxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Albert Ou <aou@xxxxxxxxxxxxxxxxx>
Cc: Alexandre Ghiti <alex@xxxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Cc: Athira Rajeev <atrajeev@xxxxxxxxxxxxx>
Cc: Chun-Tse Shao <ctshao@xxxxxxxxxx>
Cc: Dmitriy Vyukov <dvyukov@xxxxxxxxxx>
Cc: Dr. David Alan Gilbert <linux@xxxxxxxxxxx>
Cc: Guo Ren <guoren@xxxxxxxxxx>
Cc: Haibo Xu <haibo1.xu@xxxxxxxxx>
Cc: Howard Chu <howardchu95@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: James Clark <james.clark@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: John Garry <john.g.garry@xxxxxxxxxx>
Cc: Krzysztof Łopatowski <krzysztof.m.lopatowski@xxxxxxxxx>
Cc: Leo Yan <leo.yan@xxxxxxxxx>
Cc: Mark Wielaard <mark@xxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Palmer Dabbelt <palmer@xxxxxxxxxxx>
Cc: Paul Walmsley <pjw@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Sergei Trofimovich <slyich@xxxxxxxxx>
Cc: Shimin Guo <shimin.guo@xxxxxxxxxx>
Cc: Stephen Brennan <stephen.s.brennan@xxxxxxxxxx>
Cc: Thomas Falcon <thomas.falcon@xxxxxxxxx>
Cc: Will Deacon <will@xxxxxxxxxx>
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
tools/perf/util/symbol-elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index d1dcafa4b3b80..439f252937b89 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -1173,7 +1173,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
Elf *embedded = read_gnu_debugdata(dso, elf, name, &new_fd);

if (!embedded)
- goto out_close;
+ goto out_elf_end;

elf_end(elf);
close(fd);
--
2.51.0