From 53cc63f0c91ce9f6f9c81f87e2673c5adfe1afe7 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 25 Feb 2021 09:03:24 +0100 Subject: [PATCH] std: Clear old memory on free Re-enable the clear-on-free step, it was previously disabled due to translate-c using freed memory. --- lib/std/mem/Allocator.zig | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index 11fab03cee..6cc888fa10 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -146,12 +146,8 @@ fn moveBytes( assert(new_len > 0); const new_mem = try self.allocFn(self, new_len, new_alignment, len_align, return_address); @memcpy(new_mem.ptr, old_mem.ptr, math.min(new_len, old_mem.len)); - // TODO DISABLED TO AVOID BUGS IN TRANSLATE C - // TODO see also https://github.com/ziglang/zig/issues/4298 - // use './zig build test-translate-c' to reproduce, some of the symbols in the - // generated C code will be a sequence of 0xaa (the undefined value), meaning - // it is printing data that has been freed - //@memset(old_mem.ptr, undefined, old_mem.len); + // TODO https://github.com/ziglang/zig/issues/4298 + @memset(old_mem.ptr, undefined, old_mem.len); _ = self.shrinkBytes(old_mem, old_align, 0, 0, return_address); return new_mem; }