diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 8a61852dde..c5e8e35466 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -778,7 +778,9 @@ proc deallocBigChunk(a: var MemRegion, c: PBigChunk) = sysAssert a.occ >= 0, "rawDealloc: negative occupied memory (case B)" when not defined(gcDestructors): a.deleted = getBottom(a) - del(a, a.root, cast[int](addr(c.data))) + # Use the same address that was added during allocation (accounting for alignment) + let alignedDataAddr = cast[int](addr(c.data)) +% c.alignOffset.int + del(a, a.root, alignedDataAddr) if c.size >= HugeChunkSize: freeHugeChunk(a, c) else: freeBigChunk(a, c) diff --git a/tests/align/talign.nim b/tests/align/talign.nim index 9c4c238098..6397e31214 100644 --- a/tests/align/talign.nim +++ b/tests/align/talign.nim @@ -123,49 +123,49 @@ for q in 0..500: z[i].a = q doAssert(cast[int](z[i]) mod alignof(MyType64) == 0) -# type -# MyType128 = object -# a{.align(128).}: int +type + MyType128 = object + a{.align(128).}: int -# var w: array[10, ref MyType128] -# for q in 0..500: -# for i in 0..