1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:47:35 +00:00

LibJS: Make BlockAllocator use free() on non-Serenity platforms

If we use aligned_alloc() to allocate, we have to use free() to free.
This commit is contained in:
Andreas Kling 2021-05-27 20:06:47 +02:00
parent 9b699bad94
commit 606b483231

View file

@ -20,10 +20,14 @@ BlockAllocator::BlockAllocator()
BlockAllocator::~BlockAllocator() BlockAllocator::~BlockAllocator()
{ {
for (auto* block : m_blocks) { for (auto* block : m_blocks) {
#ifdef __serenity__
if (munmap(block, HeapBlock::block_size) < 0) { if (munmap(block, HeapBlock::block_size) < 0) {
perror("munmap"); perror("munmap");
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
#else
free(block);
#endif
} }
} }
@ -45,10 +49,14 @@ void BlockAllocator::deallocate_block(void* block)
{ {
VERIFY(block); VERIFY(block);
if (m_blocks.size() >= max_cached_blocks) { if (m_blocks.size() >= max_cached_blocks) {
#ifdef __serenity__
if (munmap(block, HeapBlock::block_size) < 0) { if (munmap(block, HeapBlock::block_size) < 0) {
perror("munmap"); perror("munmap");
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
#else
free(block);
#endif
return; return;
} }