| ... | ... | @@ -59,6 +59,8 @@ pub const DirectAllocator = struct { |
| 59 | 59 | |
| 60 | 60 | fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 { |
| 61 | 61 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 62 | if (n == 0) |
| 63 | return (([*]u8)(undefined))[0..0]; |
| 62 | 64 | |
| 63 | 65 | switch (builtin.os) { |
| 64 | 66 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| ... | ... | @@ -140,7 +142,9 @@ pub const DirectAllocator = struct { |
| 140 | 142 | } |
| 141 | 143 | const result = try alloc(allocator, new_size, new_align); |
| 142 | 144 | @memcpy(result.ptr, old_mem.ptr, std.math.min(old_mem.len, result.len)); |
| 143 | | _ = os.posix.munmap(@ptrToInt(old_mem.ptr), old_mem.len); |
| 145 | if (old_mem.len > 0) { |
| 146 | _ = os.posix.munmap(@ptrToInt(old_mem.ptr), old_mem.len); |
| 147 | } |
| 144 | 148 | return result; |
| 145 | 149 | }, |
| 146 | 150 | Os.windows => { |