mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 21:43:40 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
b573ef3813
commit
213d10838f
@@ -47,8 +47,14 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
|
||||
gcTotalAlloc += uint64(size)
|
||||
gcMallocs++
|
||||
heapptr += size
|
||||
for heapptr >= heapEnd {
|
||||
if heapptr < addr {
|
||||
// The allocation size overflowed the heap pointer.
|
||||
runtimePanic("out of memory")
|
||||
}
|
||||
for heapptr > heapEnd {
|
||||
// Try to increase the heap and check again.
|
||||
// Use > instead of >= because an allocation that exactly
|
||||
// ends at heapEnd is still within heap boundaries.
|
||||
if growHeap() {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user