From: Tobias Klauser Date: Thu, 18 Aug 2022 17:15:51 +0000 (+0200) Subject: runtime/pprof: check Getrusage return value in addMaxRSS X-Git-Tag: go1.20rc1~1497 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2e06019dcd82c1c525c805af687063875d4b223b;p=gostls13.git runtime/pprof: check Getrusage return value in addMaxRSS 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 Auto-Submit: Tobias Klauser Reviewed-by: Joedian Reid TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- diff --git a/src/runtime/pprof/pprof_rusage.go b/src/runtime/pprof/pprof_rusage.go index 984a32e79d..a3ca4c8d5d 100644 --- a/src/runtime/pprof/pprof_rusage.go +++ b/src/runtime/pprof/pprof_rusage.go @@ -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) + } }