zig
zig copied to clipboard
Fix GeneralPurposeAllocator crash when deallocating metadata
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.