]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid stat underflow crash
authorAustin Clements <austin@google.com>
Mon, 16 Nov 2015 04:09:16 +0000 (23:09 -0500)
committerAustin Clements <austin@google.com>
Mon, 16 Nov 2015 17:32:29 +0000 (17:32 +0000)
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>
src/runtime/malloc.go

index 6430511d7db86d310a2666b713590f912bb4a232..8ce420a653d76ef7fad4b0e94082103a5eef8bba 100644 (file)
@@ -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)
                        }
                }