diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 73abd706e9..3c0f1d00eb 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -101,7 +101,7 @@ class Stack { void ShrinkToFit() { if (Empty()) { // If the stack is empty, completely deallocate the memory. - Allocator::Free(stack_); // NOLINT (+clang-analyzer-unix.Malloc) + allocator_->Free(stack_); // NOLINT (+clang-analyzer-unix.Malloc) stack_ = 0; stackTop_ = 0; stackEnd_ = 0; @@ -206,7 +206,8 @@ class Stack { } void Destroy() { - Allocator::Free(stack_); + if (allocator_) + allocator_->Free(stack_); RAPIDJSON_DELETE(ownAllocator_); // Only delete if it is owned by the stack }