zig icon indicating copy to clipboard operation
zig copied to clipboard

std: Fix GeneralPurposeAllocator double free stack traces

Open Frojdholm opened this issue 9 months ago • 1 comments

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;
    }
}

Frojdholm avatar May 16 '24 22:05 Frojdholm