diff --git a/src/cmd/covdata/covdata.go b/src/cmd/covdata/covdata.go index 95bc30d25d..549efea20a 100644 --- a/src/cmd/covdata/covdata.go +++ b/src/cmd/covdata/covdata.go @@ -176,7 +176,12 @@ func main() { if err := pprof.StartCPUProfile(f); err != nil { fatal("%v", err) } - atExit(pprof.StopCPUProfile) + atExit(func() { + pprof.StopCPUProfile() + if err = f.Close(); err != nil { + fatal("error closing cpu profile: %v", err) + } + }) } if *memprofileflag != "" { if *memprofilerateflag != 0 { @@ -192,6 +197,9 @@ func main() { if err := pprof.Lookup("heap").WriteTo(f, writeLegacyFormat); err != nil { fatal("%v", err) } + if err = f.Close(); err != nil { + fatal("error closing memory profile: %v", err) + } }) } else { // Not doing memory profiling; disable it entirely.