diff options
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/mheap.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index 711c7790eb..3334099092 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -2534,7 +2534,15 @@ func getOrAddWeakHandle(p unsafe.Pointer) *atomic.Uintptr { s := (*specialWeakHandle)(mheap_.specialWeakHandleAlloc.alloc()) unlock(&mheap_.speciallock) - handle := new(atomic.Uintptr) + // N.B. Pad the weak handle to ensure it doesn't share a tiny + // block with any other allocations. This can lead to leaks, such + // as in go.dev/issue/76007. As an alternative, we could consider + // using the currently-unused 8-byte noscan size class. + type weakHandleBox struct { + h atomic.Uintptr + _ [maxTinySize - unsafe.Sizeof(atomic.Uintptr{})]byte + } + handle := &(new(weakHandleBox).h) s.special.kind = _KindSpecialWeakHandle s.handle = handle handle.Store(uintptr(p)) |
