From 8fdd277fe6ee1770b12650a4bc2bc257e49c8065 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Tue, 10 May 2022 15:09:12 +0000 Subject: [PATCH] runtime: profile finalizer G more carefully in goroutine profile 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 Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Rhys Hiltner --- src/runtime/mprof.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/mprof.go b/src/runtime/mprof.go index cd63bafebb..2046e9f245 100644 --- a/src/runtime/mprof.go +++ b/src/runtime/mprof.go @@ -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() -- 2.50.0