diff --git a/beast/container/detail/aged_ordered_container.h b/beast/container/detail/aged_ordered_container.h index 0f04921f64..8fc672f1b7 100644 --- a/beast/container/detail/aged_ordered_container.h +++ b/beast/container/detail/aged_ordered_container.h @@ -389,11 +389,26 @@ private: template element* new_element (Args&&... args) { - element* const p ( - ElementAllocatorTraits::allocate (m_config.alloc(), 1)); + struct Deleter + { + std::reference_wrapper a_; + Deleter (ElementAllocator& a) + : a_(a) + { + } + + void + operator()(element* p) + { + ElementAllocatorTraits::deallocate (a_.get(), p, 1); + } + }; + + std::unique_ptr p (ElementAllocatorTraits::allocate ( + m_config.alloc(), 1), Deleter(m_config.alloc())); ElementAllocatorTraits::construct (m_config.alloc(), - p, clock().now(), std::forward (args)...); - return p; + p.get(), clock().now(), std::forward (args)...); + return p.release(); } void delete_element (element const* p) diff --git a/beast/container/detail/aged_unordered_container.h b/beast/container/detail/aged_unordered_container.h index 095462dea8..ca2355df64 100644 --- a/beast/container/detail/aged_unordered_container.h +++ b/beast/container/detail/aged_unordered_container.h @@ -577,11 +577,26 @@ private: template element* new_element (Args&&... args) { - element* const p ( - ElementAllocatorTraits::allocate (m_config.alloc(), 1)); + struct Deleter + { + std::reference_wrapper a_; + Deleter (ElementAllocator& a) + : a_(a) + { + } + + void + operator()(element* p) + { + ElementAllocatorTraits::deallocate (a_.get(), p, 1); + } + }; + + std::unique_ptr p (ElementAllocatorTraits::allocate ( + m_config.alloc(), 1), Deleter(m_config.alloc())); ElementAllocatorTraits::construct (m_config.alloc(), - p, clock().now(), std::forward (args)...); - return p; + p.get(), clock().now(), std::forward (args)...); + return p.release(); } void delete_element (element const* p)