From: Austin Clements Date: Fri, 11 Dec 2015 22:50:02 +0000 (-0500) Subject: runtime: check for spanBytesAlloc underflow X-Git-Tag: go1.6beta1~83 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c1cbe5b577b1bfdc34be18f391ab82904b6530f2;p=gostls13.git runtime: check for spanBytesAlloc underflow Change-Id: I5e6739ff0c6c561195ed9891fb90f933b81e7750 Reviewed-on: https://go-review.googlesource.com/17746 Run-TryBot: Austin Clements Reviewed-by: Russ Cox --- 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) {