From c1cbe5b577b1bfdc34be18f391ab82904b6530f2 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 11 Dec 2015 17:50:02 -0500 Subject: [PATCH] runtime: check for spanBytesAlloc underflow Change-Id: I5e6739ff0c6c561195ed9891fb90f933b81e7750 Reviewed-on: https://go-review.googlesource.com/17746 Run-TryBot: Austin Clements Reviewed-by: Russ Cox --- src/runtime/mgcsweep.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index 22f51dbc1a..2cf6def338 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -393,7 +393,9 @@ func reimburseSweepCredit(unusableBytes uintptr) { // Nobody cares about the credit. Avoid the atomic. return } - atomic.Xadd64(&mheap_.spanBytesAlloc, -int64(unusableBytes)) + if int64(atomic.Xadd64(&mheap_.spanBytesAlloc, -int64(unusableBytes))) < 0 { + throw("spanBytesAlloc underflow") + } } func dumpFreeList(s *mspan) { -- 2.50.0