From 17942925f56aa74469b99351b0b6b2db6af338ad Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 25 Dec 2024 17:56:37 +0100 Subject: [PATCH] Fix bug in temp allocator when temp memory is exhausted and allocation needs overaligned mem. #1715 --- lib/std/core/allocators/temp_allocator.c3 | 4 +++- releasenotes.md | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/std/core/allocators/temp_allocator.c3 b/lib/std/core/allocators/temp_allocator.c3 index 7b7e4b69d..6b8ac49b8 100644 --- a/lib/std/core/allocators/temp_allocator.c3 +++ b/lib/std/core/allocators/temp_allocator.c3 @@ -179,8 +179,10 @@ fn void*! TempAllocator.acquire(&self, usz size, AllocInitType init_type, usz al { mem = allocator::malloc_aligned(self.backing_allocator, total_alloc_size, alignment)!; } + void* start = mem; + mem += mem::aligned_offset(TempAllocatorPage.sizeof, alignment); page = (TempAllocatorPage*)mem - 1; - page.start = mem; + page.start = start; page.size = size | PAGE_IS_ALIGNED; } else diff --git a/releasenotes.md b/releasenotes.md index 2a8708781..77c54369c 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -20,6 +20,7 @@ - Fix CRT detection on Arch Linux. - Fix lexer allowing a trailing underscore (_) with hex and binary literals. - Fix `--list-operators` CLI command printing underscore (_) and hash (#). +- Fix bug in temp allocator when temp memory is exhausted and allocation needs overaligned mem. #1715 ### Stdlib changes - Increase BitWriter.write_bits limit up to 32 bits.