Skip to content

Commit

Permalink
runtime: fix upper bound on out-of-memory print
Browse files Browse the repository at this point in the history
It's possible for arena_start+MaxArena32 to wrap.
We do the right thing in the bounds check but not in the print.

For golang#13992 (to fix the print there, not the bug).

Change-Id: I4df845d0c03f0f35461b128e4f6765d3ccb71c6d
Reviewed-on: https://go-review.googlesource.com/18975
Run-TryBot: Russ Cox <[email protected]>
Reviewed-by: Austin Clements <[email protected]>
  • Loading branch information
rsc committed Jan 27, 2016
1 parent d9fdbf4 commit 26397f1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/runtime/malloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,11 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
}

if p < h.arena_start || uintptr(p)+p_size-h.arena_start >= _MaxArena32 {
print("runtime: memory allocated by OS (", hex(p), ") not in usable range [", hex(h.arena_start), ",", hex(h.arena_start+_MaxArena32), ")\n")
top := ^uintptr(0)
if top-h.arena_start > _MaxArena32 {
top = h.arena_start + _MaxArena32
}
print("runtime: memory allocated by OS (", hex(p), ") not in usable range [", hex(h.arena_start), ",", hex(top), ")\n")
sysFree(unsafe.Pointer(p), p_size, &memstats.heap_sys)
return nil
}
Expand Down

0 comments on commit 26397f1

Please sign in to comment.