]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: profile finalizer G more carefully in goroutine profile
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 10 May 2022 15:09:12 +0000 (15:09 +0000)
committerMichael Knyszek <mknyszek@google.com>
Tue, 10 May 2022 15:43:40 +0000 (15:43 +0000)
If SetFinalizer is never called, we might readgstatus on a nil fing
variable, resulting in a crash. This change guards code that accesses
fing by a nil check.

Fixes #52821.

Change-Id: I3e8e7004f97f073dc622e801a1d37003ea153a29
Reviewed-on: https://go-review.googlesource.com/c/go/+/405475
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Rhys Hiltner <rhys@justin.tv>
src/runtime/mprof.go

index cd63bafebb84a73ea03873a5bf79d8cd49591bbc..2046e9f2457c3764dfc434c324da0c036ce944bf 100644 (file)
@@ -952,9 +952,9 @@ func goroutineProfileWithLabelsConcurrent(p []StackRecord, labels []unsafe.Point
        // system goroutine (to be excluded). Pick one before restarting the world.
        if fing != nil {
                fing.goroutineProfiled.Store(goroutineProfileSatisfied)
-       }
-       if readgstatus(fing) != _Gdead && !isSystemGoroutine(fing, false) {
-               doRecordGoroutineProfile(fing)
+               if readgstatus(fing) != _Gdead && !isSystemGoroutine(fing, false) {
+                       doRecordGoroutineProfile(fing)
+               }
        }
        startTheWorld()