Fixes issue #93

This commit is contained in:
Ion Gaztañaga
2018-12-01 12:58:54 +01:00
parent 51669a5330
commit 43c0257871
2 changed files with 2 additions and 8 deletions

View File

@@ -1263,6 +1263,7 @@ use [*Boost.Container]? There are several reasons for that:
* [@https://github.com/boostorg/container/pull/86 GitHub #86: ['"Add missing warning re-enabling include"]].
* [@https://github.com/boostorg/container/issues/89 GitHub #89: ['"UBSAN failures detected in preflight CI PR"]].
* [@https://github.com/boostorg/container/issues/90 GitHub #90: ['"Build fails on clang-5 with libstdc++7-dev (C++17 issue)"]].
* [@https://github.com/boostorg/container/issues/93 GitHub #93: ['"vector::erase memory leak"]].
[endsect]

View File

@@ -2413,17 +2413,10 @@ class vector
const bool propagate_alloc = allocator_traits_type::propagate_on_container_move_assignment::value;
const bool is_propagable_from_x = is_propagable_from(x_alloc, x.m_holder.start(), this_alloc, propagate_alloc);
const bool is_propagable_from_t = is_propagable_from(this_alloc, m_holder.start(), x_alloc, propagate_alloc);
const bool are_both_propagable = is_propagable_from_x && is_propagable_from_t;
//Resources can be transferred if both allocators are
//going to be equal after this function (either propagated or already equal)
if(are_both_propagable){
//Destroy objects but retain memory in case x reuses it in the future
this->clear();
this->m_holder.swap_resources(x.m_holder);
}
else if(is_propagable_from_x){
if(is_propagable_from_x){
this->clear();
if(BOOST_LIKELY(!!this->m_holder.m_start))
this->m_holder.deallocate(this->m_holder.m_start, this->m_holder.m_capacity);