From 4e3fadd90ea6ddb24b5f98b049ad3374d1db0ab8 Mon Sep 17 00:00:00 2001 From: Brian Orora Date: Sat, 24 Jan 2026 20:10:45 +0300 Subject: [PATCH] std.heap.DebugAllocator: fix account `total_requested_bytes` on `resizeSmall` --- lib/std/heap/debug_allocator.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/std/heap/debug_allocator.zig b/lib/std/heap/debug_allocator.zig index c5abf6709c..3ea4a28f96 100644 --- a/lib/std/heap/debug_allocator.zig +++ b/lib/std/heap/debug_allocator.zig @@ -1010,7 +1010,14 @@ pub fn DebugAllocator(comptime config: Config) type { size_class_index: usize, ) bool { const new_size_class_index: usize = @max(@bitSizeOf(usize) - @clz(new_len - 1), @intFromEnum(alignment)); - if (!config.safety) return new_size_class_index == size_class_index; + if (!config.safety) { + if (new_size_class_index != size_class_index) return false; + // Still account for total even if safety is off + if (config.enable_memory_limit) + self.total_requested_bytes = self.total_requested_bytes - memory.len + new_len; + return true; + } + const slot_count = slot_counts[size_class_index]; const memory_addr = @intFromPtr(memory.ptr); const page_addr = memory_addr & ~(page_size - 1);