Skip to content

Commit 97dc591

Browse files
committed
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]>
1 parent 9b299c1 commit 97dc591

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
@@ -414,7 +414,10 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
414414
h.arena_used = used
415415
h.arena_reserved = reserved
416416
} else {
417-
var stat uint64
417+
// We haven't added this allocation to
418+
// the stats, so subtract it from a
419+
// fake stat (but avoid underflow).
420+
stat := uint64(p_size)
418421
sysFree(unsafe.Pointer(p), p_size, &stat)
419422
}
420423
}

0 commit comments

Comments
 (0)