aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mprof.go
diff options
context:
space:
mode:
authorFelix Geisendörfer <felix.geisendoerfer@datadoghq.com>2024-08-30 08:17:19 +0200
committerCarlos Amedee <carlos@golang.org>2024-09-25 17:31:06 +0000
commit49e542aa85b7c2d9f6cf50de00843b455bc1e635 (patch)
tree4d17738ea9b5241025c1b29ba00228e48a093563 /src/runtime/mprof.go
parentc64ca8c6ef13723b9f25f4b5e1c7b6986b958d2e (diff)
downloadgo-49e542aa85b7c2d9f6cf50de00843b455bc1e635.tar.xz
runtime: fix GoroutineProfile stacks not getting null terminated
Fix a regression introduced in CL 572396 causing goroutine stacks not getting null terminated. This bug impacts callers that reuse the []StackRecord slice for multiple calls to GoroutineProfile. See https://github.com/felixge/fgprof/issues/33 for an example of the problem. Add a test case to prevent similar regressions in the future. Use null padding instead of null termination to be consistent with other profile types and because it's less code to implement. Also fix the ThreadCreateProfile code path. Fixes #69243 Change-Id: I0b9414f6c694c304bc03a5682586f619e9bf0588 Reviewed-on: https://go-review.googlesource.com/c/go/+/609815 Reviewed-by: Tim King <taking@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/mprof.go')
-rw-r--r--src/runtime/mprof.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/runtime/mprof.go b/src/runtime/mprof.go
index 59267f5eaf..970533eb02 100644
--- a/src/runtime/mprof.go
+++ b/src/runtime/mprof.go
@@ -1277,7 +1277,8 @@ func pprof_mutexProfileInternal(p []profilerecord.BlockProfileRecord) (n int, ok
// of calling ThreadCreateProfile directly.
func ThreadCreateProfile(p []StackRecord) (n int, ok bool) {
return threadCreateProfileInternal(len(p), func(r profilerecord.StackRecord) {
- copy(p[0].Stack0[:], r.Stack)
+ i := copy(p[0].Stack0[:], r.Stack)
+ clear(p[0].Stack0[i:])
p = p[1:]
})
}
@@ -1656,7 +1657,8 @@ func GoroutineProfile(p []StackRecord) (n int, ok bool) {
return
}
for i, mr := range records[0:n] {
- copy(p[i].Stack0[:], mr.Stack)
+ l := copy(p[i].Stack0[:], mr.Stack)
+ clear(p[i].Stack0[l:])
}
return
}