From 22f5e5fd3e7f4cf15c38c2b3be0b0e357854026a Mon Sep 17 00:00:00 2001 From: tgschultz Date: Sat, 20 Apr 2019 17:24:40 +0000 Subject: [PATCH] Fixes DirectAllocator Windows implementation to call HeapFree when new_size == 0 --- std/heap.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/std/heap.zig b/std/heap.zig index 472bf5e523..143429eea1 100644 --- a/std/heap.zig +++ b/std/heap.zig @@ -151,6 +151,13 @@ pub const DirectAllocator = struct { const old_record_addr = old_adjusted_addr + old_mem.len; const root_addr = @intToPtr(*align(1) usize, old_record_addr).*; const old_ptr = @intToPtr(*c_void, root_addr); + + if(new_size == 0) + { + if(os.windows.HeapFree(self.heap_handle.?, 0, old_ptr) == 0) unreachable; + return old_mem[0..0]; + } + const amt = new_size + new_align + @sizeOf(usize); const new_ptr = os.windows.HeapReAlloc( self.heap_handle.?,