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

Tengda Wu posted 1 patch 1 week ago
tools/perf/util/llvm.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm()
Posted by Tengda Wu 1 week ago
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, &notes->src->source);
 
-- 
2.34.1
Re: [PATCH] perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm()
Posted by Ian Rogers 3 days, 7 hours ago
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, &notes->src->source);
>
> --
> 2.34.1
>