diff --git a/AK/BumpAllocator.h b/AK/BumpAllocator.h index cd2f4f4d95e..7526ec9a7ad 100644 --- a/AK/BumpAllocator.h +++ b/AK/BumpAllocator.h @@ -91,7 +91,7 @@ protected: if (head_chunk == m_current_chunk) VERIFY(chunk_header.next_chunk == 0); auto next_chunk = chunk_header.next_chunk; - fn(head_chunk); + fn(head_chunk + sizeof(ChunkHeader)); head_chunk = next_chunk; } } @@ -179,13 +179,13 @@ public: void destroy_all() { this->for_each_chunk([&](auto chunk) { - auto base_ptr = align_up_to(chunk + sizeof(typename Allocator::ChunkHeader), alignof(T)); + auto base_ptr = align_up_to(chunk, alignof(T)); // Compute the offset of the first byte *after* this chunk: FlatPtr end_offset = base_ptr + this->m_chunk_size - chunk; + if (chunk == this->m_current_chunk + sizeof(typename Allocator::ChunkHeader)) + end_offset = this->m_byte_offset_into_current_chunk; // Compute the offset of the first byte *after* the last valid object, in case the end of the chunk does not align with the end of an object: end_offset = (end_offset / sizeof(T)) * sizeof(T); - if (chunk == this->m_current_chunk) - end_offset = this->m_byte_offset_into_current_chunk; for (; base_ptr - chunk < end_offset; base_ptr += sizeof(T)) reinterpret_cast(base_ptr)->~T(); });