From 2e06019dcd82c1c525c805af687063875d4b223b Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 18 Aug 2022 19:15:51 +0200 Subject: [PATCH] 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 --- src/runtime/pprof/pprof_rusage.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) + } } -- 2.50.0