[PATCH] perf intel-bts: Free the old snapshot reference array after growing it
From: lirongqing
Date: Tue Nov 03 2026 - 21:25:08 EST
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;
--
2.9.4