zig icon indicating copy to clipboard operation
zig copied to clipboard

Fix GeneralPurposeAllocator crash when deallocating metadata

Open Frojdholm opened this issue 9 months ago • 2 comments

Fixes #19977

This makes the following test not crash

const std = @import("std");

test "retain metadata and never unmap" {
    var gpa = std.heap.GeneralPurposeAllocator(.{
        .safety = true,
        .never_unmap = true,
        .retain_metadata = true,
    }){};
    defer std.debug.assert(gpa.deinit() == .ok);
    const allocator = gpa.allocator();

    const alloc = try allocator.alloc(u8, 8);
    allocator.free(alloc);

    const alloc2 = try allocator.alloc(u8, 8);
    allocator.free(alloc2);
}

The getMin/getMax -> remove pattern could be encapsulated in a function popMin/popMax that return the removed key.

Frojdholm avatar May 19 '24 11:05 Frojdholm