From 28eed1f7b3a8654b941960232d7c707d88649d8d Mon Sep 17 00:00:00 2001 From: dweiller <4678790+dweiller@users.noreplay.github.com> Date: Thu, 8 Jun 2023 13:30:28 +1000 Subject: [PATCH] std.mem.ValidationAllocator: forward free() calls Failing to forward free calls to the underlying allocator makes `ValidationAllocator` unusable for testing allocators while checking for leaks. This change allows allocators that wrap `std.testing.allocator` to be tested with `std.heap.testAllocator()` in test decls without reporting erroneous leaks. --- lib/std/mem.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/mem.zig b/lib/std/mem.zig index d6ca4a9ea1..43cca6aab9 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -96,10 +96,10 @@ pub fn ValidationAllocator(comptime T: type) type { log2_buf_align: u8, ret_addr: usize, ) void { - _ = ctx; - _ = log2_buf_align; - _ = ret_addr; + const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx)); assert(buf.len > 0); + const underlying = self.getUnderlyingAllocatorPtr(); + underlying.rawFree(buf, log2_buf_align, ret_addr); } pub fn reset(self: *Self) void {