Re: [PATCH] perf intel-bts: Free the old snapshot reference array after growing it
From: Arnaldo Carvalho de Melo
Date: Wed Nov 04 2026 - 18:56:56 EST
On Wed, Nov 04, 2026 at 10:00:15AM +0000, James Clark wrote:
>
>
> On 04/11/2026 02:20, lirongqing wrote:
> > From: Li RongQing <lirongqing@xxxxxxxxx>
> >
> > The snapshot reference array grows when a mapping index exceeds its
> > capacity. Its old entries are copied into a new allocation, but the old
> > array is abandoned when snapshot_refs is replaced.
> >
> > Release the old array after copying it so expanding past sixteen
> > mappings does not leak it.
> >
> > Fixes: d0170af7004d ("perf tools: Add Intel BTS support")
> > Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
> > ---
> > tools/perf/arch/x86/util/intel-bts.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
> > index d44d568..9403681 100644
> > --- a/tools/perf/arch/x86/util/intel-bts.c
> > +++ b/tools/perf/arch/x86/util/intel-bts.c
> > @@ -299,6 +299,7 @@ static int intel_bts_alloc_snapshot_refs(struct intel_bts_recording *btsr,
> > memcpy(refs, btsr->snapshot_refs, cnt * sz);
> > + free(btsr->snapshot_refs);
> > btsr->snapshot_refs = refs;
> > btsr->snapshot_ref_cnt = new_cnt;
>
> I made the same fix here [1] as well as turning BTS snapshots into the
> generic one. But that doesn't have a fixes tag, so maybe this patch is still
> useful.
>
> Reviewed-by: James Clark <james.clark@xxxxxxxxxx>
>
> [1]: https://lore.kernel.org/all/20261102-james-cs-unformatted-per-thread-fix-v3-10-dbcb0c281b9b@xxxxxxxxxx/
Thanks, applied for v7.4.
- Arnaldo