authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-02-25 09:03:24+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-02-25 22:20:30+02:00
log53cc63f0c91ce9f6f9c81f87e2673c5adfe1afe7
tree2135fcf617a8b7c2136740160f3dc3b547d27b78
parent449f4de3825d3448c2aa0cda79c1a567adb08b59

std: Clear old memory on free

Re-enable the clear-on-free step, it was previously disabled due to translate-c using freed memory.

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

lib/std/mem/Allocator.zig+2-6
...@@ -146,12 +146,8 @@ fn moveBytes(...@@ -146,12 +146,8 @@ fn moveBytes(
146 assert(new_len > 0);146 assert(new_len > 0);
147 const new_mem = try self.allocFn(self, new_len, new_alignment, len_align, return_address);147 const new_mem = try self.allocFn(self, new_len, new_alignment, len_align, return_address);
148 @memcpy(new_mem.ptr, old_mem.ptr, math.min(new_len, old_mem.len));148 @memcpy(new_mem.ptr, old_mem.ptr, math.min(new_len, old_mem.len));
149 // TODO DISABLED TO AVOID BUGS IN TRANSLATE C149 // TODO https://github.com/ziglang/zig/issues/4298
150 // TODO see also https://github.com/ziglang/zig/issues/4298150 @memset(old_mem.ptr, undefined, old_mem.len);
151 // use './zig build test-translate-c' to reproduce, some of the symbols in the
152 // generated C code will be a sequence of 0xaa (the undefined value), meaning
153 // it is printing data that has been freed
154 //@memset(old_mem.ptr, undefined, old_mem.len);
155 _ = self.shrinkBytes(old_mem, old_align, 0, 0, return_address);151 _ = self.shrinkBytes(old_mem, old_align, 0, 0, return_address);
156 return new_mem;152 return new_mem;
157}153}