Re: [PATCH 08/12] perf jitdump: Fix debug_data and unwinding_data leaks

From: Ian Rogers

Date: Wed Aug 05 2026 - 15:10:51 EST


On Wed, Aug 5, 2026 at 6:31 AM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
>
> From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
>
> jit_repipe_debug_info() overwrites jd->debug_data without freeing the
> previous allocation. If two consecutive JIT_CODE_DEBUG_INFO records
> appear without an intervening LOAD record consuming the data, the first
> allocation leaks.
>
> The sibling jit_repipe_unwinding_info() already frees the old
> jd->unwinding_data before reassignment — add the same pattern to
> jit_repipe_debug_info() using zfree().
>
> Also add cleanup of both buffers in jit_close() so they are freed when
> the jitdump session ends, even if no LOAD record consumed them.
>
> Fixes: 9b07e27f88b9 ("perf inject: Add jitdump mmap injection support")
> Reported-by: sashiko-bot <sashiko-bot@xxxxxxxxxx>
> Cc: Stephane Eranian <eranian@xxxxxxxxxx>
> Assisted-by: Claude:claude-opus-4.6
> Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>

Thanks!
Ian

> ---
> tools/perf/util/jitdump.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
> index 4f52b143cd0da296..3085091b95a517ae 100644
> --- a/tools/perf/util/jitdump.c
> +++ b/tools/perf/util/jitdump.c
> @@ -118,6 +118,8 @@ jit_close(struct jit_buf_desc *jd)
> funlockfile(jd->in);
> fclose(jd->in);
> jd->in = NULL;
> + zfree(&jd->debug_data);
> + zfree(&jd->unwinding_data);
> }
>
> static int
> @@ -706,6 +708,7 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr)
>
> memcpy(data, &jr->info.entries, sz);
>
> + zfree(&jd->debug_data);
> jd->debug_data = data;
>
> /*
> --
> 2.55.0
>