[PATCH] perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm()

From: Tengda Wu

Date: Thu Sep 17 2026 - 08:58:32 EST


In symbol__disassemble_llvm(), after calling llvm_addr2line(), if the
subsequent disasm_line__new() fails, the code directly jumps to 'err'
without freeing args->fileloc, leading to a memory leak.

Fix this by explicitly calling free(args->fileloc) before jumping to
the error handling path when disasm_line__new() fails.

Fixes: 048856817888 ("perf annotate: LLVM-based disassembler")
Signed-off-by: Tengda Wu <wutengda@xxxxxxxxxxxxxxx>
---
tools/perf/util/llvm.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/llvm.c b/tools/perf/util/llvm.c
index a0deb742a733..dc66f6cc1db6 100644
--- a/tools/perf/util/llvm.c
+++ b/tools/perf/util/llvm.c
@@ -254,8 +254,10 @@ int symbol__disassemble_llvm(const char *filename, struct symbol *sym,
(unsigned int *)&args->line_nr, false, NULL);

dl = disasm_line__new(args);
- if (dl == NULL)
+ if (dl == NULL) {
+ free(args->fileloc);
goto err;
+ }

annotation_line__add(&dl->al, &notes->src->source);

--
2.34.1