authorgravatar for hampus.frojdholm@gmail.comHampus Fröjdholm <hampus.frojdholm@gmail.com> 2024-05-18 11:46:37+02:00
committergravatar for hampus.frojdholm@gmail.comHampus Fröjdholm <hampus.frojdholm@gmail.com> 2024-05-18 11:46:37+02:00
log762e2a4b52084beb41fb4a0d34d55f5a907db00a
tree54c5d698e4dd1bf48a5992393d984ef534bd0b0c
parent61f1b2db704c9bfa96c6a965fdba57cf3692b2c9

gpa: Fix GeneralPurposeAllocator double free stack traces

The wrong `size_class` was used when fetching stack traces from empty buckets. The `size_class` would always be the maximum value after exhausting the search of active buckets rather than the actual `size_class` of the allocation.

1 files changed, 2 insertions(+), 0 deletions(-)

lib/std/heap/general_purpose_allocator.zig+2
......@@ -732,6 +732,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
732732 if (!self.large_allocations.contains(@intFromPtr(old_mem.ptr))) {
733733 // object not in active buckets or a large allocation, so search empty buckets
734734 if (searchBucket(&self.empty_buckets, @intFromPtr(old_mem.ptr), null)) |bucket| {
735 size_class = bucket.emptyBucketSizeClass();
735736 // bucket is empty so is_used below will always be false and we exit there
736737 break :blk bucket;
737738 } else {
......@@ -850,6 +851,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
850851 if (!self.large_allocations.contains(@intFromPtr(old_mem.ptr))) {
851852 // object not in active buckets or a large allocation, so search empty buckets
852853 if (searchBucket(&self.empty_buckets, @intFromPtr(old_mem.ptr), null)) |bucket| {
854 size_class = bucket.emptyBucketSizeClass();
853855 // bucket is empty so is_used below will always be false and we exit there
854856 break :blk bucket;
855857 } else {