Skip to content

Commit e493309

Browse files
committed
[release-branch.go1.5] 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 <[email protected]> Reviewed-on: https://go-review.googlesource.com/16987 Run-TryBot: Austin Clements <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 20a0536 commit e493309

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/runtime/malloc.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ func mHeap_SysAlloc(h *mheap, n uintptr) unsafe.Pointer {
411411
h.arena_used = used
412412
h.arena_reserved = reserved
413413
} else {
414-
var stat uint64
414+
// We haven't added this allocation to
415+
// the stats, so subtract it from a
416+
// fake stat (but avoid underflow).
417+
stat := uint64(p_size)
415418
sysFree((unsafe.Pointer)(p), p_size, &stat)
416419
}
417420
}

0 commit comments

Comments
 (0)