tools/perf/util/llvm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
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@huaweicloud.com>
---
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, ¬es->src->source);
--
2.34.1
On Thu, Sep 17, 2026 at 5:58 AM Tengda Wu <wutengda@huaweicloud.com> wrote:
>
> 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@huaweicloud.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> 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, ¬es->src->source);
>
> --
> 2.34.1
>
© 2016 - 2026 Red Hat, Inc.