runtime: handle nil pointer in sysFreeOS on sbrk platforms

On sbrk platforms (Plan 9 and Wasm), sysReserveOS
returns nil when it can't reserve memory at the
requested hint address. When the caller passes that
nil result to sysUnreserve, sysFreeOS reaches
memFree(nil), which clears the region with
memclrNoHeapPointers, writing to address 0.

On Plan 9, this faults the program with a
"sys: trap: fault write" note. It is reproducible
on plan9/amd64 with TestArenaCollision, which
exhausts the arena hints and unreserves the failed
reservations.

On mmap-based platforms, sysUnreserve(nil) is a
harmless munmap(nil). This change makes sysFreeOS
return early for a nil pointer, so freeing or
unreserving nil is a no-op on sbrk platforms too.

Change-Id: I2e3057a5bb34254d600d05b5fa128c77960d4e9a
Reviewed-on: https://go-review.googlesource.com/c/go/+/793400
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Richard Miller <millerresearch@gmail.com>
1 file changed
tree: de422aa5f9adea5ea3c69ee300e05df0a91021e9
  1. .github/
  2. api/
  3. doc/
  4. lib/
  5. misc/
  6. src/
  7. test/
  8. .gitattributes
  9. .gitignore
  10. codereview.cfg
  11. CONTRIBUTING.md
  12. go.env
  13. LICENSE
  14. PATENTS
  15. README.md
  16. SECURITY.md
README.md

The Go Programming Language

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Gopher image Gopher image by Renee French, licensed under Creative Commons 4.0 Attribution license.

Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

Download and Install

Binary Distributions

Official binary distributions are available at https://go.dev/dl/.

After downloading a binary release, visit https://go.dev/doc/install for installation instructions.

Install From Source

If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.

Contributing

Go is the work of thousands of contributors. We appreciate your help!

To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.

Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.