From 606b4832312c659615ce813077844ebe5ac2b4a4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 27 May 2021 20:06:47 +0200 Subject: [PATCH] LibJS: Make BlockAllocator use free() on non-Serenity platforms If we use aligned_alloc() to allocate, we have to use free() to free. --- Userland/Libraries/LibJS/Heap/BlockAllocator.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Userland/Libraries/LibJS/Heap/BlockAllocator.cpp b/Userland/Libraries/LibJS/Heap/BlockAllocator.cpp index 8d0977fa0b..1e50414b88 100644 --- a/Userland/Libraries/LibJS/Heap/BlockAllocator.cpp +++ b/Userland/Libraries/LibJS/Heap/BlockAllocator.cpp @@ -20,10 +20,14 @@ BlockAllocator::BlockAllocator() BlockAllocator::~BlockAllocator() { for (auto* block : m_blocks) { +#ifdef __serenity__ if (munmap(block, HeapBlock::block_size) < 0) { perror("munmap"); VERIFY_NOT_REACHED(); } +#else + free(block); +#endif } } @@ -45,10 +49,14 @@ void BlockAllocator::deallocate_block(void* block) { VERIFY(block); if (m_blocks.size() >= max_cached_blocks) { +#ifdef __serenity__ if (munmap(block, HeapBlock::block_size) < 0) { perror("munmap"); VERIFY_NOT_REACHED(); } +#else + free(block); +#endif return; }