Boost C++ Libraries: Ticket #9185: boost::container::vector leaks memory https://svn.boost.org/trac10/ticket/9185 <p> boost::container::vector may leak memory with allocation of size 0. For example, on Debian with libboost1.54-dev 1.54.0-2, with this program: </p> <pre class="wiki">#include &lt;boost/container/vector.hpp&gt; int main() { using namespace boost::container; vector&lt;int&gt; v1; vector&lt;int&gt; v2(v1); return 0; } </pre><p> I have </p> <pre class="wiki">$ valgrind --leak-check=full ./test ==15591== Memcheck, a memory error detector ==15591== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. ==15591== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info ==15591== Command: ./test ==15591== ==15591== ==15591== HEAP SUMMARY: ==15591== in use at exit: 0 bytes in 1 blocks ==15591== total heap usage: 1 allocs, 0 frees, 0 bytes allocated ==15591== ==15591== 0 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==15591== at 0x4C298F9: operator new(unsigned long) (vg_replace_malloc.c:298) ==15591== by 0x4017F6: __gnu_cxx::new_allocator&lt;int&gt;::allocate(unsigned long, void const*) (new_allocator.h:104) ==15591== by 0x4015FC: boost::container::container_detail::allocator_version_traits&lt;std::allocator&lt;int&gt;, 1u&gt;::allocation_command(std::allocator&lt;int&gt;&amp;, int, unsigned long, unsigned long, unsigned long&amp;, int* const&amp;) (allocator_version_traits.hpp:144) ==15591== by 0x401542: boost::container::container_detail::vector_alloc_holder&lt;std::allocator&lt;int&gt;, boost::container::container_detail::integral_constant&lt;unsigned int, 1u&gt; &gt;::allocation_command(int, unsigned long, unsigned long, unsigned long&amp;, int* const&amp;) (vector.hpp:395) ==15591== by 0x401474: boost::container::container_detail::vector_alloc_holder&lt;std::allocator&lt;int&gt;, boost::container::container_detail::integral_constant&lt;unsigned int, 1u&gt; &gt;::vector_alloc_holder&lt;std::allocator&lt;int&gt; &gt;(std::allocator&lt;int&gt; const&amp;, unsigned long) (vector.hpp:350) ==15591== by 0x401104: boost::container::container_detail::vector_alloc_holder&lt;std::allocator&lt;int&gt;, boost::container::container_detail::integral_constant&lt;unsigned int, 1u&gt; &gt;::vector_alloc_holder&lt;std::allocator&lt;int&gt; &gt;(std::allocator&lt;int&gt; const&amp;, unsigned long) (vector.hpp:351) ==15591== by 0x401007: boost::container::vector&lt;int, std::allocator&lt;int&gt; &gt;::vector(boost::container::vector&lt;int, std::allocator&lt;int&gt; &gt; const&amp;) (vector.hpp:732) ==15591== by 0x400F6C: boost::container::vector&lt;int, std::allocator&lt;int&gt; &gt;::vector(boost::container::vector&lt;int, std::allocator&lt;int&gt; &gt; const&amp;) (vector.hpp:737) ==15591== by 0x400EBB: main (test.cpp:10) ==15591== ==15591== LEAK SUMMARY: ==15591== definitely lost: 0 bytes in 1 blocks ==15591== indirectly lost: 0 bytes in 0 blocks ==15591== possibly lost: 0 bytes in 0 blocks ==15591== still reachable: 0 bytes in 0 blocks ==15591== suppressed: 0 bytes in 0 blocks ==15591== ==15591== For counts of detected and suppressed errors, rerun with: -v ==15591== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2) </pre><p> I suspect that </p> <pre class="wiki"> ~vector_alloc_holder() BOOST_CONTAINER_NOEXCEPT { if(this-&gt;m_capacity){ this-&gt;alloc().deallocate(this-&gt;m_start, this-&gt;m_capacity); } } </pre><p> should be </p> <pre class="wiki"> ~vector_alloc_holder() BOOST_CONTAINER_NOEXCEPT { if(this-&gt;m_start){ this-&gt;alloc().deallocate(this-&gt;m_start, this-&gt;m_capacity); } } </pre><p> (not tested). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9185 Trac 1.4.3 Ion Gaztañaga Wed, 02 Oct 2013 20:30:28 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9185#comment:1 https://svn.boost.org/trac10/ticket/9185#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> <p> Thanks for the report, it's a duplicate of <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9166" title="#9166: Bugs: Memory leak when copying empty boost::container::vector (closed: fixed)">#9166</a> which is fixed on trunk and release branches for Boost 1.55. </p> Ticket