aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2015-11-15 23:09:16 -0500
committerAustin Clements <austin@google.com>2015-11-16 17:32:29 +0000
commit97dc591534e580ede4c6145456dadf1e009f1bea (patch)
tree84f38b17a74e0a11adc1f25d0ec26b7399cbbfa5 /src/runtime/malloc.go
parent9b299c1efd902842b788d7dc103512b6b2568ea9 (diff)
downloadgo-97dc591534e580ede4c6145456dadf1e009f1bea.tar.xz
runtime: avoid stat underflow crash
If the area returned by sysReserve in mheap.sysAlloc is outside the usable arena, we sysFree it. We pass a fake stat pointer to sysFree because we haven't added the allocation to any stat at that point. However, we pass a 0 stat, so sysFree panics when it decrements the stat because the fake stat underflows. Fix this by setting the fake stat to the allocation size. Updates #13143 (this is a prerequisite to fixing that bug). Change-Id: I61a6c9be19ac1c95863cf6a8435e19790c8bfc9a Reviewed-on: https://go-review.googlesource.com/16926 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 6430511d7d..8ce420a653 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -414,7 +414,10 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
h.arena_used = used
h.arena_reserved = reserved
} else {
- var stat uint64
+ // We haven't added this allocation to
+ // the stats, so subtract it from a
+ // fake stat (but avoid underflow).
+ stat := uint64(p_size)
sysFree(unsafe.Pointer(p), p_size, &stat)
}
}