Skip to content

Commit 82726cb

Browse files
fix block deallocation bug
1 parent c84c3e9 commit 82726cb

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

include/nbl/core/alloc/SimpleBlockBasedAllocator.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,12 @@ class SimpleBlockBasedAllocator<AddressAllocator,void*> final : protected BlockB
280280
inline void deallocate(void* p, const size_type bytes) noexcept
281281
{
282282
assert(m_blocks.size()>=base_t::m_initBlockCount);
283-
auto found = m_blocks.lower_bound(reinterpret_cast<block_t*>(p));
284-
assert(found!=m_blocks.end());
283+
// pointer can be in the block, but will be past the (block start is in the block)
284+
auto found = m_blocks.upper_bound(reinterpret_cast<block_t*>(p));
285+
assert(found!=m_blocks.begin());
286+
// need to rewind by one
287+
found--;
288+
// and now we've got our block
285289
auto* block = *found;
286290
uint8_t* blockData = block->data(base_t::m_blockCreationParams);
287291
assert(blockData<=p && p<blockData+base_t::m_blockCreationParams.blockSize);

0 commit comments

Comments
 (0)