From d3b8b2f38db7c1f93892e4822942b1f86f01ed8e Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 7 May 2006 10:06:47 +0000 Subject: [PATCH] Fix a bug in allocator_constructor. [SVN r2949] --- include/boost/unordered/detail/allocator.hpp | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/include/boost/unordered/detail/allocator.hpp b/include/boost/unordered/detail/allocator.hpp index aac39b3a..8ff1c1f6 100644 --- a/include/boost/unordered/detail/allocator.hpp +++ b/include/boost/unordered/detail/allocator.hpp @@ -119,9 +119,10 @@ namespace boost { Allocator& alloc_; pointer ptr_; + bool constructed_; allocator_constructor(Allocator& a) - : alloc_(a), ptr_() + : alloc_(a), ptr_(), constructed_(false) { #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) unordered_detail::reset(ptr_); @@ -129,23 +130,25 @@ namespace boost { } ~allocator_constructor() { - if (ptr_) alloc_.deallocate(ptr_, 1); + if(ptr_) { + if(constructed_) alloc_.destroy(ptr_); + alloc_.deallocate(ptr_, 1); + } } template - pointer construct(V const& v) { - BOOST_ASSERT(!ptr_); - pointer p = alloc_.allocate(1); - ptr_ = p; - alloc_.construct(p, v); - reset(ptr_); - return p; + void construct(V const& v) { + BOOST_ASSERT(!ptr_ && !constructed_); + ptr_ = alloc_.allocate(1); + alloc_.construct(ptr_, v); + constructed_ = true; } // no throw pointer release() { pointer p = ptr_; + constructed_ = false; reset(ptr_); return p; }