mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 09:03:12 +00:00
Fix issue 5741, use after free
This commit is contained in:
parent
374e3e42e0
commit
c2eead9629
@ -714,6 +714,11 @@ test "PageAllocator" {
|
||||
slice[127] = 0x34;
|
||||
allocator.free(slice);
|
||||
}
|
||||
{
|
||||
var buf = try allocator.alloc(u8, mem.page_size + 1);
|
||||
defer allocator.free(buf);
|
||||
buf = try allocator.realloc(buf, 1); // shrink past the page boundary
|
||||
}
|
||||
}
|
||||
|
||||
test "HeapAllocator" {
|
||||
|
@ -116,9 +116,6 @@ pub const Allocator = struct {
|
||||
if (isAligned(@ptrToInt(old_mem.ptr), new_alignment)) {
|
||||
if (new_byte_count <= old_mem.len) {
|
||||
const shrunk_len = self.shrinkBytes(old_mem, new_byte_count, len_align);
|
||||
if (shrunk_len < old_mem.len) {
|
||||
@memset(old_mem.ptr + shrunk_len, undefined, old_mem.len - shrunk_len);
|
||||
}
|
||||
return old_mem.ptr[0..shrunk_len];
|
||||
}
|
||||
if (self.callResizeFn(old_mem, new_byte_count, len_align)) |resized_len| {
|
||||
|
Loading…
Reference in New Issue
Block a user