runtime: Fix panic when trying to stop CPU profiling with profiler turned off Fixes #7063. R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/47950043
diff --git a/src/pkg/runtime/cpuprof.c b/src/pkg/runtime/cpuprof.c index 1c34b9e..040ffcd 100644 --- a/src/pkg/runtime/cpuprof.c +++ b/src/pkg/runtime/cpuprof.c
@@ -168,7 +168,7 @@ runtime·noteclear(&prof->wait); runtime·setcpuprofilerate(tick, hz); - } else if(prof->on) { + } else if(prof != nil && prof->on) { runtime·setcpuprofilerate(nil, 0); prof->on = false;
diff --git a/src/pkg/runtime/runtime_test.go b/src/pkg/runtime/runtime_test.go index f6b48ba..c673275 100644 --- a/src/pkg/runtime/runtime_test.go +++ b/src/pkg/runtime/runtime_test.go
@@ -126,3 +126,8 @@ t.Fatalf("go tool nm did not report size for runtime.gogo") } + +// golang.org/issue/7063 +func TestStopCPUProfilingWithProfilerOff(t *testing.T) { + SetCPUProfileRate(0) +}