From: Joel Sing Date: Sat, 26 Sep 2015 17:56:05 +0000 (+1000) Subject: runtime: handle sysReserve failure in mHeap_SysAlloc X-Git-Tag: go1.6beta1~942 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1d5251f707af711720cbd92891a1d62b89c15977;p=gostls13.git runtime: handle sysReserve failure in mHeap_SysAlloc sysReserve will return nil on failure - correctly handle this case and return nil to the caller. Currently, a failure will result in h.arena_end being set to psize, h.arena_used being set to zero and fun times ensue. On the openbsd/arm builder this has resulted in: runtime: address space conflict: map(0x0) = 0x40946000 fatal error: runtime: address space conflict When it should be reporting out of memory instead. Change-Id: Iba828d5ee48ee1946de75eba409e0cfb04f089d4 Reviewed-on: https://go-review.googlesource.com/15056 Reviewed-by: Brad Fitzpatrick Reviewed-by: Austin Clements --- diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 353f84083f..f038debdd3 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -398,6 +398,9 @@ func mHeap_SysAlloc(h *mheap, n uintptr) unsafe.Pointer { // is reserved and part is not. var reserved bool p := uintptr(sysReserve((unsafe.Pointer)(h.arena_end), p_size, &reserved)) + if p == 0 { + return nil + } if p == h.arena_end { h.arena_end = new_end h.arena_reserved = reserved