authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-09-20 00:10:53+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-20 01:21:29-04:00
log58ee5f4e61cd9b7a9ba65798e2214efa3753a733
tree783d36ae80c34a91c50d1e5f7768e6116cd6583b
parentf92d01c8a86b525c2caaf07497e16841905cea8c

std: Fix metadata corruption in HeapAllocator

HeapAllocator stores the pointer returned by HeapAlloc right after the data block and, after the recent allocator refactoring, the space for this pointer was not taken into account in the calculation of the final block size. Fixes #5830

1 files changed, 1 insertions(+), 1 deletions(-)

lib/std/heap.zig+1-1
......@@ -489,7 +489,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
489489 const full_len = os.windows.kernel32.HeapSize(heap_handle, 0, ptr);
490490 assert(full_len != std.math.maxInt(usize));
491491 assert(full_len >= amt);
492 break :init mem.alignBackwardAnyAlign(full_len - (aligned_addr - root_addr), len_align);
492 break :init mem.alignBackwardAnyAlign(full_len - (aligned_addr - root_addr) - @sizeOf(usize), len_align);
493493 };
494494 const buf = @intToPtr([*]u8, aligned_addr)[0..return_len];
495495 getRecordPtr(buf).* = root_addr;