boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
101 stars 113 forks source link

Allocations not handled correctly in some cases of vector move with unequal allocators #145

Closed ergpudb closed 4 years ago

ergpudb commented 4 years ago

When move assigning or move constructing a vector from another vector with an unequal, non-propagating allocator, there are cases where memory ends up not being allocated from the correct allocators and the system ends up in an invalid state.

The attached reproducer demonstrates this for two test cases. Both use a vector<vector> with a scoped allocator that counts allocations and deallocations. The first test case uses move assignment, the second uses move construction with specified allocator. In both cases, using boost vectors, the allocators end up in a nonzero state when all vectors are destroyed. Using STL vectors in gcc 5 w/ C++11 ABI (and presumably newer versions), the allocators end up in a zero state at the end as they should.

test.cpp.txt

igaztanaga commented 4 years ago

Many thanks for the report. There is a bug on vector's extended move constructor which considers passed allocator equal to the internal one. Fixing it and improving tests to catch these type of errors.