diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2025-04-01 19:38:39 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-05-20 11:13:54 -0700 |
| commit | 913c069819b77c0cfda78806654696508baf7f32 (patch) | |
| tree | a2c91b6dea8214a35d5dab2c917bf6e512d404a6 /src/runtime/testdata | |
| parent | dfebef1c0459af0a34eceb4027c9fab5824f2eab (diff) | |
| download | go-913c069819b77c0cfda78806654696508baf7f32.tar.xz | |
runtime: annotate checkfinalizers reports with source and type info
This change adds a new special kind called CheckFinalizer which is used
to annotate finalizers and cleanups with extra information about where
that cleanup or finalizer came from.
For #72949.
Change-Id: I3c1ace7bd580293961b7f0ea30345a6ce956d340
Reviewed-on: https://go-review.googlesource.com/c/go/+/662135
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/testdata')
| -rw-r--r-- | src/runtime/testdata/testprog/checkfinalizers.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/runtime/testdata/testprog/checkfinalizers.go b/src/runtime/testdata/testprog/checkfinalizers.go index ef0108a7e0..410a0f6a23 100644 --- a/src/runtime/testdata/testprog/checkfinalizers.go +++ b/src/runtime/testdata/testprog/checkfinalizers.go @@ -6,6 +6,7 @@ package main import ( "runtime" + "runtime/debug" ) func init() { @@ -16,6 +17,8 @@ func init() { func DetectFinalizerAndCleanupLeaks() { type T *int + defer debug.SetGCPercent(debug.SetGCPercent(-1)) + // Leak a cleanup. cLeak := new(T) runtime.AddCleanup(cLeak, func(x int) { @@ -26,6 +29,11 @@ func DetectFinalizerAndCleanupLeaks() { cNoLeak := new(T) runtime.AddCleanup(cNoLeak, func(_ int) {}, int(0)) + // Add a cleanup that only temporarily leaks cNoLeak. + runtime.AddCleanup(cNoLeak, func(x int) { + **cNoLeak = x + }, int(0)).Stop() + // Leak a finalizer. fLeak := new(T) runtime.SetFinalizer(fLeak, func(_ *T) { |
