Skip to content

Commit 213d108

Browse files
digitalentitydeadprogram
authored andcommitted
fix(gc): correct leaking allocator bounds and overflow checks.
Change heap-end comparison to > to prevent spurious OOM when heapptr exactly matches heapEnd. Add overflow check to prevent heap wrapping.
1 parent b573ef3 commit 213d108

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/runtime/gc_leaking.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
4747
gcTotalAlloc += uint64(size)
4848
gcMallocs++
4949
heapptr += size
50-
for heapptr >= heapEnd {
50+
if heapptr < addr {
51+
// The allocation size overflowed the heap pointer.
52+
runtimePanic("out of memory")
53+
}
54+
for heapptr > heapEnd {
5155
// Try to increase the heap and check again.
56+
// Use > instead of >= because an allocation that exactly
57+
// ends at heapEnd is still within heap boundaries.
5258
if growHeap() {
5359
continue
5460
}

0 commit comments

Comments
 (0)