Skip to content

Commit 78ce3a0

Browse files
committed
reflect: use a bigger object when we need a finalizer to run
If an object is allocated as part of a tinyalloc, then other live objects in the same tinyalloc chunk keep the finalizer from being run, even if the object that has the finalizer is dead. Make sure the object we're setting the finalizer on is big enough to not trigger tinyalloc allocation. Fixes #26857 Update #21717 Change-Id: I56ad8679426283237ebff20a0da6c9cf64eb1c27 Reviewed-on: https://go-review.googlesource.com/128475 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 776298a commit 78ce3a0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/reflect/all_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,9 +1693,9 @@ func TestCallReturnsEmpty(t *testing.T) {
16931693
// nonzero-sized frame and zero-sized return value.
16941694
runtime.GC()
16951695
var finalized uint32
1696-
f := func() (emptyStruct, *int) {
1697-
i := new(int)
1698-
runtime.SetFinalizer(i, func(*int) { atomic.StoreUint32(&finalized, 1) })
1696+
f := func() (emptyStruct, *[2]int64) {
1697+
i := new([2]int64) // big enough to not be tinyalloc'd, so finalizer always runs when i dies
1698+
runtime.SetFinalizer(i, func(*[2]int64) { atomic.StoreUint32(&finalized, 1) })
16991699
return emptyStruct{}, i
17001700
}
17011701
v := ValueOf(f).Call(nil)[0] // out[0] should not alias out[1]'s memory, so the finalizer should run.

0 commit comments

Comments
 (0)