mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm()
@ 2026-09-17 12:58 Tengda Wu
  2026-09-21 18:36 ` Ian Rogers
  0 siblings, 1 reply; 4+ messages in thread
From: Tengda Wu @ 2026-09-17 12:58 UTC (permalink / raw)
  To: Namhyung Kim, james.clark, xueshuai, Ian Rogers, Adrian Hunter
  Cc: Peter Zijlstra, leo.yan, Li Huafei, Kim Phillips, Mark Rutland,
	Arnaldo Carvalho de Melo, Ingo Molnar, Bill Wendling,
	Nick Desaulniers, Alexander Shishkin, Zecheng Li,
	linux-perf-users, linux-kernel, llvm, Tengda Wu

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm()
  2026-09-17 12:58 [PATCH] perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm() Tengda Wu
@ 2026-09-21 18:36 ` Ian Rogers
  2026-09-25  9:56   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Rogers @ 2026-09-21 18:36 UTC (permalink / raw)
  To: Tengda Wu
  Cc: Namhyung Kim, james.clark, xueshuai, Adrian Hunter,
	Peter Zijlstra, leo.yan, Li Huafei, Kim Phillips, Mark Rutland,
	Arnaldo Carvalho de Melo, Ingo Molnar, Bill Wendling,
	Nick Desaulniers, Alexander Shishkin, Zecheng Li,
	linux-perf-users, linux-kernel, llvm

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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm()
  2026-09-21 18:36 ` Ian Rogers
@ 2026-09-25  9:56   ` Arnaldo Carvalho de Melo
  2026-09-25  9:59     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-09-25  9:56 UTC (permalink / raw)
  To: Tengda Wu, Ian Rogers
  Cc: Steinar H. Gunderson, Namhyung Kim, james.clark, xueshuai,
	Adrian Hunter, Peter Zijlstra, leo.yan, Li Huafei, Kim Phillips,
	Mark Rutland, Ingo Molnar, Bill Wendling, Nick Desaulniers,
	Alexander Shishkin, Zecheng Li, linux-perf-users, linux-kernel,
	llvm

On Mon, Sep 21, 2026 at 11:36:08AM -0700, Ian Rogers wrote:
> 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>

I replaced the free() with a zfree(&), minor.

Thanks, applied to perf-tools-next, for v7.4.

- Arnaldo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm()
  2026-09-25  9:56   ` Arnaldo Carvalho de Melo
@ 2026-09-25  9:59     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-09-25  9:59 UTC (permalink / raw)
  To: Tengda Wu, Ian Rogers
  Cc: Steinar H. Gunderson, Namhyung Kim, james.clark, xueshuai,
	Adrian Hunter, Peter Zijlstra, leo.yan, Li Huafei, Kim Phillips,
	Mark Rutland, Ingo Molnar, Bill Wendling, Nick Desaulniers,
	Alexander Shishkin, Zecheng Li, linux-perf-users, linux-kernel,
	llvm

On Fri, Sep 25, 2026 at 11:56:04AM +0200, Arnaldo Carvalho de Melo wrote:
> On Mon, Sep 21, 2026 at 11:36:08AM -0700, Ian Rogers wrote:
> > 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>
> 
> I replaced the free() with a zfree(&), minor.

I understand why you didn't use zfree(), to make it consistent with the
other free, will keep it and leave the zfree() for later.

Sorry about the noise,

- Arnaldo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-25  9:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 12:58 [PATCH] perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm() Tengda Wu
2026-09-21 18:36 ` Ian Rogers
2026-09-25  9:56   ` Arnaldo Carvalho de Melo
2026-09-25  9:59     ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®