]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: check Getrusage return value in addMaxRSS
authorTobias Klauser <tklauser@distanz.ch>
Thu, 18 Aug 2022 17:15:51 +0000 (19:15 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 19 Aug 2022 20:04:40 +0000 (20:04 +0000)
Depending on the implementation of the getrusage syscall/function, the
value of rusage.Maxrss may be undefined in case of an error. Thus, only
report MaxRSS in case of no error.

Change-Id: I7572ccc53c49eb460e53bded3eb41736eed8d2ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/424815
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/runtime/pprof/pprof_rusage.go

index 984a32e79d4561eb91e1d343eaa8c14d1fcfb195..a3ca4c8d5dd7ebbf0546a2a0e6b8cdb6b7007825 100644 (file)
@@ -28,6 +28,8 @@ func addMaxRSS(w io.Writer) {
        }
 
        var rusage syscall.Rusage
-       syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
-       fmt.Fprintf(w, "# MaxRSS = %d\n", uintptr(rusage.Maxrss)*rssToBytes)
+       err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
+       if err == nil {
+               fmt.Fprintf(w, "# MaxRSS = %d\n", uintptr(rusage.Maxrss)*rssToBytes)
+       }
 }