Skip to content

Commit 1d94b61

Browse files
committed
benchprof: fix nil pointer exception
A bug in `benchprof.StartAllProfiles` has been fixed that caused nil pointer exceptions. Additionally, `benchprof.StartAllProfiles` no longer allocates a do-nothing `StopFn`. Release note: None
1 parent 4fa3974 commit 1d94b61

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pkg/bench/benchprof/benchprof.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ func (f StopFn) Stop(tb testing.TB) {
4444
// })
4545
// }
4646
func StartAllProfiles(tb testing.TB) StopFn {
47-
cpuStop := StartCPUProfile(tb)
48-
memStop := StartMemProfile(tb)
49-
mutexStop := StartMutexProfile(tb)
47+
cpuStopper := StartCPUProfile(tb)
48+
memStopper := StartMemProfile(tb)
49+
mutexStopper := StartMutexProfile(tb)
50+
if cpuStopper == nil && memStopper == nil && mutexStopper == nil {
51+
return nil
52+
}
5053
return func(b testing.TB) {
51-
cpuStop(b)
52-
memStop(b)
53-
mutexStop(b)
54+
cpuStopper.Stop(b)
55+
memStopper.Stop(b)
56+
mutexStopper.Stop(b)
5457
}
5558
}
5659

0 commit comments

Comments
 (0)