1
0
mirror of https://github.com/golang/go synced 2024-07-08 12:18:55 +00:00

cmd/compile: close files in the startProfile function

Signed-off-by: guoguangwu <guoguangwug@gmail.com>
This commit is contained in:
guoguangwu 2024-03-30 11:41:51 +08:00
parent 1f354a60ff
commit 239b28e857

View File

@ -39,7 +39,12 @@ func startProfile() {
if err := pprof.StartCPUProfile(f); err != nil {
base.Fatalf("%v", err)
}
base.AtExit(pprof.StopCPUProfile)
base.AtExit(func() {
pprof.StopCPUProfile()
if err = f.Close(); err != nil {
base.Fatalf("error closing cpu profile: %v", err)
}
})
}
if base.Flag.MemProfile != "" {
if base.Flag.MemProfileRate != 0 {
@ -77,6 +82,9 @@ func startProfile() {
if err := pprof.Lookup("heap").WriteTo(f, format); err != nil {
base.Fatalf("%v", err)
}
if err = f.Close(); err != nil {
base.Fatalf("error closing memory profile: %v", err)
}
})
} else {
// Not doing memory profiling; disable it entirely.
@ -112,6 +120,11 @@ func startProfile() {
if err := tracepkg.Start(f); err != nil {
base.Fatalf("%v", err)
}
base.AtExit(tracepkg.Stop)
base.AtExit(func() {
tracepkg.Stop()
if err = f.Close(); err != nil {
base.Fatalf("error closing trace profile: %v", err)
}
})
}
}