diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index b7042a53c..f615ffd99 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -143,11 +143,13 @@ class MemoryPoolAllocator { //! Deallocates all memory chunks, excluding the user-supplied buffer. void Clear() { - while(chunkHead_ != 0 && chunkHead_ != userBuffer_) { + while (chunkHead_ && chunkHead_ != userBuffer_) { ChunkHeader* next = chunkHead_->next; baseAllocator_->Free(chunkHead_); chunkHead_ = next; } + if (chunkHead_ && chunkHead_ == userBuffer_) + chunkHead_->size = 0; // Clear user buffer } //! Computes the total capacity of allocated memory chunks.