From 3dc40a8f3452c8e97790e927e751712c23f115ed Mon Sep 17 00:00:00 2001 From: miloyip Date: Sun, 10 May 2015 22:54:47 +0800 Subject: [PATCH] Fix MemoryPoolAllocator::Clear() to clear user-buffer --- include/rapidjson/allocators.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index b7042a5..f615ffd 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -143,11 +143,13 @@ public: //! 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.