Boost C++ Libraries: Ticket #12296: boost::container::{deque,string} combine for a memory leak https://svn.boost.org/trac10/ticket/12296 <p> The following program leaks memory, according to valgrind. Switching either deque or string (or both) to the std:: implementation does not show the leak, so I'm not sure which container has the bug (though I suspect it's deque). </p> <pre class="wiki">$ cat foo.cpp #include &lt;boost/container/deque.hpp&gt; #include &lt;boost/container/string.hpp&gt; #include &lt;deque&gt; #include &lt;string&gt; using boost::container::deque; using boost::container::string; // using std::deque; // using std::string; int main() { deque&lt;string&gt; foo; foo.push_back("------------------------"); foo.push_back("------------------------"); foo.erase(foo.begin(), foo.begin() + 1); return 0; } $ g++ -std=c++11 -g -Wall foo.cpp &amp;&amp; valgrind --leak-check=full ./a.out ==29864== Memcheck, a memory error detector ==29864== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==29864== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==29864== Command: ./a.out ==29864== ==29864== ==29864== HEAP SUMMARY: ==29864== in use at exit: 72,752 bytes in 2 blocks ==29864== total heap usage: 5 allocs, 3 frees, 73,368 bytes allocated ==29864== ==29864== 48 bytes in 1 blocks are definitely lost in loss record 1 of 2 ==29864== at 0x4C2B0D8: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==29864== by 0x405A12: boost::container::new_allocator&lt;char&gt;::allocate(unsigned long) (new_allocator.hpp:145) ==29864== by 0x405047: boost::container::container_detail::allocator_version_traits&lt;boost::container::new_allocator&lt;char&gt;, 1u&gt;::allocation_command(boost::container::new_allocator&lt;char&gt;&amp;, unsigned int, unsigned long, unsigned long&amp;, char*&amp;) (allocator_version_traits.hpp:142) ==29864== by 0x404647: boost::container::container_detail::basic_string_base&lt;boost::container::new_allocator&lt;char&gt; &gt;::allocation_command(unsigned int, unsigned long, unsigned long&amp;, char*&amp;) (string.hpp:276) ==29864== by 0x403823: boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::container::new_allocator&lt;char&gt; &gt;::priv_reserve(unsigned long, bool) (string.hpp:2494) ==29864== by 0x40250B: boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::container::new_allocator&lt;char&gt; &gt;::reserve(unsigned long) (string.hpp:1088) ==29864== by 0x401922: boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::container::new_allocator&lt;char&gt; &gt;::assign(char const*, char const*) (string.hpp:1401) ==29864== by 0x4011C9: boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::container::new_allocator&lt;char&gt; &gt;::basic_string(char const*) (string.hpp:707) ==29864== by 0x400D84: main (foo.cpp:13) ==29864== ==29864== LEAK SUMMARY: ==29864== definitely lost: 48 bytes in 1 blocks ==29864== indirectly lost: 0 bytes in 0 blocks ==29864== possibly lost: 0 bytes in 0 blocks ==29864== still reachable: 72,704 bytes in 1 blocks ==29864== suppressed: 0 bytes in 0 blocks ==29864== Reachable blocks (those to which a pointer was found) are not shown. ==29864== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==29864== ==29864== For counts of detected and suppressed errors, rerun with: -v ==29864== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) </pre><p> (Ignore the "still reachable" blocks; those are from libstdc++ itself.) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12296 Trac 1.4.3 Ion Gaztañaga Mon, 01 Aug 2016 22:51:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12296#comment:1 https://svn.boost.org/trac10/ticket/12296#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">fixed</span> </li> </ul> <p> Thanks for the report. Fixed in commit: </p> <p> <a class="ext-link" href="https://github.com/boostorg/container/commit/649aba461efa2f0b7bb576e12307a4161072e8c1"><span class="icon">​</span>https://github.com/boostorg/container/commit/649aba461efa2f0b7bb576e12307a4161072e8c1</a> </p> Ticket