Skip to content

Commit 6cbd737

Browse files
runtime/pprof: update example comment to check error on Close
Programs should always check the error return of Close for a file opened for writing. Update the example code in the comment to mention this. Change-Id: I2ff6866ff1fe23b47c54268ac8e182210cc876c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/202137 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 04e80fb commit 6cbd737

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/runtime/pprof/pprof.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// if err != nil {
2929
// log.Fatal("could not create CPU profile: ", err)
3030
// }
31-
// defer f.Close()
31+
// defer f.Close() // error handling omitted for example
3232
// if err := pprof.StartCPUProfile(f); err != nil {
3333
// log.Fatal("could not start CPU profile: ", err)
3434
// }
@@ -42,7 +42,7 @@
4242
// if err != nil {
4343
// log.Fatal("could not create memory profile: ", err)
4444
// }
45-
// defer f.Close()
45+
// defer f.Close() // error handling omitted for example
4646
// runtime.GC() // get up-to-date statistics
4747
// if err := pprof.WriteHeapProfile(f); err != nil {
4848
// log.Fatal("could not write memory profile: ", err)

0 commit comments

Comments
 (0)