diff --git a/src/ArduinoJson/Memory/MemoryPool.hpp b/src/ArduinoJson/Memory/MemoryPool.hpp index 4964f8e9..110f6e02 100644 --- a/src/ArduinoJson/Memory/MemoryPool.hpp +++ b/src/ArduinoJson/Memory/MemoryPool.hpp @@ -46,16 +46,14 @@ class MemoryPool { } ~MemoryPool() { - if (_begin) - _allocator->deallocate(_begin); + deallocPool(); } MemoryPool(const MemoryPool&) = delete; MemoryPool& operator=(const MemoryPool& src) = delete; MemoryPool& operator=(MemoryPool&& src) { - if (_begin) - _allocator->deallocate(_begin); + deallocPool(); _allocator = src._allocator; _begin = src._begin; _end = src._end; @@ -265,6 +263,11 @@ class MemoryPool { ARDUINOJSON_ASSERT(isAligned(_end)); } + void deallocPool() { + if (_begin) + _allocator->deallocate(_begin); + } + Allocator* _allocator; char *_begin, *_left, *_right, *_end; bool _overflowed;