From 17176a2ceaa9ba9849671c3987588dd212377a8f Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 18 Dec 2022 17:27:23 +0100 Subject: [PATCH] runtime: zero freed memory This helps to find bugs in the GC. It does have a performance impact so it's only enabled when asserts are enabled. --- src/runtime/gc_blocks.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/gc_blocks.go b/src/runtime/gc_blocks.go index 4c7896e0..b3185b6e 100644 --- a/src/runtime/gc_blocks.go +++ b/src/runtime/gc_blocks.go @@ -168,6 +168,9 @@ func (b gcBlock) markFree() { if gcAsserts && b.state() != blockStateFree { runtimePanic("gc: markFree() was not successful") } + if gcAsserts { + *(*[wordsPerBlock]uintptr)(unsafe.Pointer(b.address())) = [wordsPerBlock]uintptr{} + } } // unmark changes the state of the block from mark to head. It must be marked