From cb9c6f007478abf491f598d4ce25c980542dd74a Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Sun, 26 Mar 2023 17:47:11 -0700 Subject: [PATCH] runtime: zero map key/value on deletion to so GC doesn't see them --- src/runtime/hashmap.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 62b4a7f59..f583d26b9 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -342,6 +342,11 @@ func hashmapDelete(m *hashmap, key unsafe.Pointer, hash uint32) { if m.keyEqual(key, slotKey, m.keySize) { // Found the key, delete it. bucket.tophash[i] = 0 + // Zero out the key and value so garbage collector doesn't pin the allocations. + memzero(slotKey, m.keySize) + slotValueOffset := unsafe.Sizeof(hashmapBucket{}) + m.keySize*8 + m.valueSize*uintptr(i) + slotValue := unsafe.Add(unsafe.Pointer(bucket), slotValueOffset) + memzero(slotValue, m.valueSize) m.count-- return }