diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2025-05-09 18:53:06 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-05-20 11:15:12 -0700 |
| commit | c58f58b9f8df0bde53bb5bc20b5ea97d34b1531d (patch) | |
| tree | 3d032baae8584ef335920ebc8febebffdfaa5927 /src/runtime/testdata | |
| parent | 913c069819b77c0cfda78806654696508baf7f32 (diff) | |
| download | go-c58f58b9f8df0bde53bb5bc20b5ea97d34b1531d.tar.xz | |
runtime: mark and identify tiny blocks in checkfinalizers mode
This change adds support for identifying cleanups and finalizers
attached to tiny blocks to checkfinalizers mode. It also notes a subtle
pitfall, which is that the cleanup arg, if tiny-allocated, could end up
co-located with the object with the cleanup attached! Oops...
For #72949.
Change-Id: Icbe0112f7dcfc63f35c66cf713216796a70121ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/662037
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Diffstat (limited to 'src/runtime/testdata')
| -rw-r--r-- | src/runtime/testdata/testprog/checkfinalizers.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/runtime/testdata/testprog/checkfinalizers.go b/src/runtime/testdata/testprog/checkfinalizers.go index 410a0f6a23..b542f575fe 100644 --- a/src/runtime/testdata/testprog/checkfinalizers.go +++ b/src/runtime/testdata/testprog/checkfinalizers.go @@ -13,6 +13,10 @@ func init() { register("DetectFinalizerAndCleanupLeaks", DetectFinalizerAndCleanupLeaks) } +type tiny uint8 + +var tinySink *tiny + // Intended to be run only with `GODEBUG=checkfinalizers=1`. func DetectFinalizerAndCleanupLeaks() { type T *int @@ -34,6 +38,15 @@ func DetectFinalizerAndCleanupLeaks() { **cNoLeak = x }, int(0)).Stop() + // Ensure we create an allocation into a tiny block that shares space among several values. + var ctLeak *tiny + for i := 0; i < 18; i++ { + tinySink = ctLeak + ctLeak = new(tiny) + *ctLeak = tiny(i) + } + runtime.AddCleanup(ctLeak, func(_ struct{}) {}, struct{}{}) + // Leak a finalizer. fLeak := new(T) runtime.SetFinalizer(fLeak, func(_ *T) { @@ -49,10 +62,4 @@ func DetectFinalizerAndCleanupLeaks() { // runtime.GC here should crash. runtime.GC() println("OK") - - // Keep everything alive. - runtime.KeepAlive(cLeak) - runtime.KeepAlive(cNoLeak) - runtime.KeepAlive(fLeak) - runtime.KeepAlive(fNoLeak) } |
