Fix a bug in allocator_constructor.

[SVN r2949]
This commit is contained in:
Daniel James
2006-05-07 10:06:47 +00:00
parent 13f2fbaf00
commit d3b8b2f38d

View File

@@ -119,9 +119,10 @@ namespace boost {
Allocator& alloc_; Allocator& alloc_;
pointer ptr_; pointer ptr_;
bool constructed_;
allocator_constructor(Allocator& a) allocator_constructor(Allocator& a)
: alloc_(a), ptr_() : alloc_(a), ptr_(), constructed_(false)
{ {
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
unordered_detail::reset(ptr_); unordered_detail::reset(ptr_);
@@ -129,23 +130,25 @@ namespace boost {
} }
~allocator_constructor() { ~allocator_constructor() {
if (ptr_) alloc_.deallocate(ptr_, 1); if(ptr_) {
if(constructed_) alloc_.destroy(ptr_);
alloc_.deallocate(ptr_, 1);
}
} }
template <class V> template <class V>
pointer construct(V const& v) { void construct(V const& v) {
BOOST_ASSERT(!ptr_); BOOST_ASSERT(!ptr_ && !constructed_);
pointer p = alloc_.allocate(1); ptr_ = alloc_.allocate(1);
ptr_ = p; alloc_.construct(ptr_, v);
alloc_.construct(p, v); constructed_ = true;
reset(ptr_);
return p;
} }
// no throw // no throw
pointer release() pointer release()
{ {
pointer p = ptr_; pointer p = ptr_;
constructed_ = false;
reset(ptr_); reset(ptr_);
return p; return p;
} }