zig
zig copied to clipboard
std: Fix GeneralPurposeAllocator double free stack traces
Fixes #19978
I wrote the following program to test different allocation sizes
const std = @import("std");
const page_size = std.mem.page_size;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{
.safety = true,
.never_unmap = true,
.retain_metadata = true,
}){};
defer std.debug.assert(gpa.deinit() == .ok);
const allocator = gpa.allocator();
var size_class: usize = 1;
while (size_class <= page_size) {
std.debug.print("allocating {}\n", .{size_class * 8});
const alloc = try allocator.alloc(u8, size_class);
allocator.free(alloc);
allocator.free(alloc);
size_class *= 2;
}
}