runtime: don't spin looking for a tiny alloc address with asan or race

CL 674655 modified the checkfinalizers test to spin looking for an
appropriate address to trip the detector, but this doesn't work with
ASAN or in race mode, which both disable the tiny allocator.

Fixes #73834.

Change-Id: I27416da1f29cd953271698551e9ce9724484c683
Reviewed-on: https://go-review.googlesource.com/c/go/+/675395
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
Michael Anthony Knyszek 2025-05-22 00:29:14 +00:00 committed by Michael Knyszek
parent bfbf736564
commit c684dfcb8a

View file

@ -5,6 +5,8 @@
package main
import (
"internal/asan"
"internal/race"
"runtime"
"runtime/debug"
"unsafe"
@ -39,7 +41,11 @@ func DetectFinalizerAndCleanupLeaks() {
**cNoLeak = x
}, int(0)).Stop()
if !asan.Enabled && !race.Enabled {
// Ensure we create an allocation into a tiny block that shares space among several values.
//
// Don't do this with ASAN and in race mode, where the tiny allocator is disabled.
// We might just loop forever here in that case.
var ctLeak *tiny
for {
tinySink = ctLeak
@ -53,6 +59,7 @@ func DetectFinalizerAndCleanupLeaks() {
}
}
runtime.AddCleanup(ctLeak, func(_ struct{}) {}, struct{}{})
}
// Leak a finalizer.
fLeak := new(T)