mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-20 04:19:04 +00:00
runtime: zero map key/value on deletion to so GC doesn't see them
This commit is contained in:
@@ -342,6 +342,11 @@ func hashmapDelete(m *hashmap, key unsafe.Pointer, hash uint32) {
|
|||||||
if m.keyEqual(key, slotKey, m.keySize) {
|
if m.keyEqual(key, slotKey, m.keySize) {
|
||||||
// Found the key, delete it.
|
// Found the key, delete it.
|
||||||
bucket.tophash[i] = 0
|
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--
|
m.count--
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user