diff --git a/src/cmd/link/internal/ld/main.go b/src/cmd/link/internal/ld/main.go index 13077668e7..5a4d7f9451 100644 --- a/src/cmd/link/internal/ld/main.go +++ b/src/cmd/link/internal/ld/main.go @@ -519,6 +519,10 @@ func startProfile() { if err := pprof.Lookup("heap").WriteTo(f, writeLegacyFormat); err != nil { log.Fatalf("%v", err) } + // Close the file after writing the profile. + if err := f.Close(); err != nil { + log.Fatalf("could not close %v: %v", *memprofile, err) + } }) } }