Re: [PATCH] perf intel-pt: Free the old snapshot reference array after growing it
From: Adrian Hunter
Date: Wed Nov 04 2026 - 04:51:31 EST
On 04/11/2026 04:19, lirongqing wrote:
> From: Li RongQing <lirongqing@xxxxxxxxx>
>
> Growing snapshot_refs allocates a new array and copies the old entries,
> then overwrites the only pointer to the old array. Snapshot recording
> with more than sixteen AUX mappings leaks that allocation on expansion.
>
> Free the old array after copying its entries. The reference buffers are
> still owned by the entries copied into the replacement array.
>
> Fixes: 90e457f7be08 ("perf tools: Add Intel PT support")
> Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
Reviewed-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
> ---
> tools/perf/arch/x86/util/intel-pt.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
> index 5e38b9c..f034e3d 100644
> --- a/tools/perf/arch/x86/util/intel-pt.c
> +++ b/tools/perf/arch/x86/util/intel-pt.c
> @@ -941,6 +941,7 @@ static int intel_pt_alloc_snapshot_refs(struct intel_pt_recording *ptr, int idx)
>
> memcpy(refs, ptr->snapshot_refs, cnt * sz);
>
> + free(ptr->snapshot_refs);
> ptr->snapshot_refs = refs;
> ptr->snapshot_ref_cnt = new_cnt;
>