From: guoguangwu Date: Wed, 17 Apr 2024 00:58:46 +0000 (+0000) Subject: cmd/covdata: close cpu and mem profile X-Git-Tag: go1.23rc1~601 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f367fea83a95c0845ed4733ab1d6ada9ba3087c7;p=gostls13.git cmd/covdata: close cpu and mem profile Change-Id: Iaf14989eb2981f724c4091f992ed99687ce3a60e GitHub-Last-Rev: 6e6c82bb8fba5c32c24eafb50eec6751a93d09f9 GitHub-Pull-Request: golang/go#66852 Reviewed-on: https://go-review.googlesource.com/c/go/+/579255 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek Reviewed-by: Emmanuel Odeke Reviewed-by: Than McIntosh Auto-Submit: Than McIntosh --- 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.