Skip to content

Commit

Permalink
std: Fix metadata corruption in HeapAllocator
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LemonBoy authored and andrewrk committed Sep 20, 2020
1 parent f92d01c commit 58ee5f4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/std/heap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
const full_len = os.windows.kernel32.HeapSize(heap_handle, 0, ptr);
assert(full_len != std.math.maxInt(usize));
assert(full_len >= amt);
break :init mem.alignBackwardAnyAlign(full_len - (aligned_addr - root_addr), len_align);
break :init mem.alignBackwardAnyAlign(full_len - (aligned_addr - root_addr) - @sizeOf(usize), len_align);
};
const buf = @intToPtr([*]u8, aligned_addr)[0..return_len];
getRecordPtr(buf).* = root_addr;
Expand Down

0 comments on commit 58ee5f4

Please sign in to comment.