mirror of
https://github.com/golang/go.git
synced 2025-10-19 19:13:18 +00:00
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:
parent
bfbf736564
commit
c684dfcb8a
1 changed files with 19 additions and 12 deletions
|
@ -5,6 +5,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"internal/asan"
|
||||||
|
"internal/race"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -39,7 +41,11 @@ func DetectFinalizerAndCleanupLeaks() {
|
||||||
**cNoLeak = x
|
**cNoLeak = x
|
||||||
}, int(0)).Stop()
|
}, int(0)).Stop()
|
||||||
|
|
||||||
|
if !asan.Enabled && !race.Enabled {
|
||||||
// Ensure we create an allocation into a tiny block that shares space among several values.
|
// 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
|
var ctLeak *tiny
|
||||||
for {
|
for {
|
||||||
tinySink = ctLeak
|
tinySink = ctLeak
|
||||||
|
@ -53,6 +59,7 @@ func DetectFinalizerAndCleanupLeaks() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runtime.AddCleanup(ctLeak, func(_ struct{}) {}, struct{}{})
|
runtime.AddCleanup(ctLeak, func(_ struct{}) {}, struct{}{})
|
||||||
|
}
|
||||||
|
|
||||||
// Leak a finalizer.
|
// Leak a finalizer.
|
||||||
fLeak := new(T)
|
fLeak := new(T)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue