From 3f5016f60e3ce7fd5c2883cf65dbbc9fbdbf9300 Mon Sep 17 00:00:00 2001 From: SirOlaf <34164198+SirOlaf@users.noreply.github.com> Date: Mon, 8 Jul 2024 11:15:53 +0200 Subject: [PATCH] Adjust the correct chunk's free space in allocator (#23795) Fixes #23788 --- lib/system/alloc.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index cc4a24d8fc..94c747e0bb 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -865,7 +865,7 @@ proc rawAlloc(a: var MemRegion, requestedSize: int): pointer = when not defined(gcDestructors): sysAssert(c.freeList.zeroField == 0, "rawAlloc 8") c.freeList = c.freeList.next - dec(c.free, size) + dec(cast[PSmallChunk](pageAddr(result)).free, size) sysAssert((cast[int](result) and (MemAlign-1)) == 0, "rawAlloc 9") sysAssert(allocInv(a), "rawAlloc: end c != nil") sysAssert(allocInv(a), "rawAlloc: before c.free < size") @@ -948,7 +948,7 @@ proc rawDealloc(a: var MemRegion, p: pointer) = inc(c.free, s) else: inc(c.free, s) - if c.free == SmallChunkSize-smallChunkOverhead(): + if c.free == SmallChunkSize-smallChunkOverhead() and a.freeSmallChunks[s div MemAlign] == c: listRemove(a.freeSmallChunks[s div MemAlign], c) c.size = SmallChunkSize freeBigChunk(a, cast[PBigChunk](c))