Skip to content

Commit 5d3df2e

Browse files
Fix possible bug when freeing blocks
1 parent d0afb30 commit 5d3df2e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

MemoryPool.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,11 @@ void CPPShift::Memory::MemoryPool::free(void* unit_pointer_start)
126126
// If block offset is 0 remove block if not the only one left
127127
if (this->currentBlock != this->firstBlock && (block->offset == 0 || block->numberOfAllocated == block->numberOfDeleted)) {
128128
if (block == this->firstBlock) this->firstBlock = block->next;
129-
else block->prev->next = block->next;
130-
if (block == this->currentBlock) this->currentBlock = block->prev;
129+
else if (block == this->currentBlock) this->currentBlock = block->prev;
130+
else {
131+
block->prev->next = block->next;
132+
block->next->prev = block->prev;
133+
}
131134
std::free(block);
132135
}
133136
}

0 commit comments

Comments
 (0)