aboutsummaryrefslogtreecommitdiff
path: root/lib/std/heap
diff options
context:
space:
mode:
authorHampus Fröjdholm <hampus.frojdholm@gmail.com>2024-05-18 11:46:37 +0200
committerHampus Fröjdholm <hampus.frojdholm@gmail.com>2024-05-18 11:46:37 +0200
commit762e2a4b52084beb41fb4a0d34d55f5a907db00a (patch)
tree54c5d698e4dd1bf48a5992393d984ef534bd0b0c /lib/std/heap
parent61f1b2db704c9bfa96c6a965fdba57cf3692b2c9 (diff)
downloadzig-762e2a4b52084beb41fb4a0d34d55f5a907db00a.tar.gz
zig-762e2a4b52084beb41fb4a0d34d55f5a907db00a.zip
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.
Diffstat (limited to 'lib/std/heap')
-rw-r--r--lib/std/heap/general_purpose_allocator.zig2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig
index 547032bbf9..9f82e03529 100644
--- a/lib/std/heap/general_purpose_allocator.zig
+++ b/lib/std/heap/general_purpose_allocator.zig
@@ -732,6 +732,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
if (!self.large_allocations.contains(@intFromPtr(old_mem.ptr))) {
// object not in active buckets or a large allocation, so search empty buckets
if (searchBucket(&self.empty_buckets, @intFromPtr(old_mem.ptr), null)) |bucket| {
+ size_class = bucket.emptyBucketSizeClass();
// bucket is empty so is_used below will always be false and we exit there
break :blk bucket;
} else {
@@ -850,6 +851,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
if (!self.large_allocations.contains(@intFromPtr(old_mem.ptr))) {
// object not in active buckets or a large allocation, so search empty buckets
if (searchBucket(&self.empty_buckets, @intFromPtr(old_mem.ptr), null)) |bucket| {
+ size_class = bucket.emptyBucketSizeClass();
// bucket is empty so is_used below will always be false and we exit there
break :blk bucket;
} else {