LibC: Don't munmap nullptr with 0 size in malloc

This commit is contained in:
2026-07-10 10:14:48 +03:00
parent efb25e5666
commit 583c2437b4

View File

@@ -264,10 +264,12 @@ void* malloc(size_t total_size)
if (new_allocators == MAP_FAILED)
goto malloc_return;
static_assert(BAN::is_trivially_copyable_v<BitmapAllocator>);
memcpy(new_allocators, s_allocators, s_allocator_count * sizeof(BitmapAllocator));
munmap(s_allocators, s_allocator_capacity * sizeof(BitmapAllocator));
if (s_allocators != nullptr)
{
static_assert(BAN::is_trivially_copyable_v<BitmapAllocator>);
memcpy(new_allocators, s_allocators, s_allocator_count * sizeof(BitmapAllocator));
munmap(s_allocators, s_allocator_capacity * sizeof(BitmapAllocator));
}
s_allocators = static_cast<BitmapAllocator*>(new_allocators);
s_allocator_capacity = new_allocator_pages * page_size / sizeof(BitmapAllocator);