Fix MemoryPoolAllocator::Clear() to clear user-buffer

This commit is contained in:
miloyip
2015-05-10 22:54:47 +08:00
committed by Milo Yip
parent 1034587235
commit 0691502573

View File

@@ -143,11 +143,13 @@ public:
//! Deallocates all memory chunks, excluding the user-supplied buffer. //! Deallocates all memory chunks, excluding the user-supplied buffer.
void Clear() { void Clear() {
while(chunkHead_ != 0 && chunkHead_ != userBuffer_) { while (chunkHead_ && chunkHead_ != userBuffer_) {
ChunkHeader* next = chunkHead_->next; ChunkHeader* next = chunkHead_->next;
baseAllocator_->Free(chunkHead_); baseAllocator_->Free(chunkHead_);
chunkHead_ = next; chunkHead_ = next;
} }
if (chunkHead_ && chunkHead_ == userBuffer_)
chunkHead_->size = 0; // Clear user buffer
} }
//! Computes the total capacity of allocated memory chunks. //! Computes the total capacity of allocated memory chunks.