From: Keith Randall Date: Wed, 8 Aug 2018 03:59:04 +0000 (-0700) Subject: reflect: use a bigger object when we need a finalizer to run X-Git-Tag: go1.12beta1~1271 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=78ce3a0368279653d05cbd1003e801363caba75a;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements Reviewed-by: Cherry Zhang --- diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 33bd75fda5..c616b37008 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -1693,9 +1693,9 @@ func TestCallReturnsEmpty(t *testing.T) { // nonzero-sized frame and zero-sized return value. runtime.GC() var finalized uint32 - f := func() (emptyStruct, *int) { - i := new(int) - runtime.SetFinalizer(i, func(*int) { atomic.StoreUint32(&finalized, 1) }) + f := func() (emptyStruct, *[2]int64) { + i := new([2]int64) // big enough to not be tinyalloc'd, so finalizer always runs when i dies + runtime.SetFinalizer(i, func(*[2]int64) { atomic.StoreUint32(&finalized, 1) }) return emptyStruct{}, i } v := ValueOf(f).Call(nil)[0] // out[0] should not alias out[1]'s memory, so the finalizer should run.