Boost C++ Libraries: Ticket #4922: memory leak in boost::iostreams::detail::chain_impl::~chain_impl() https://svn.boost.org/trac10/ticket/4922 <p> It appears that there are some cases when the <em>chain_impl::close()</em> (<strong>boost/iostreams/chain.hpp</strong>) throws an exception. If it is invoked from </p> <pre class="wiki">~chain_impl() { try { close(); reset(); } catch (...) { } } </pre><p> the following <em>reset()</em> method won't be invoked and it results in memory leak because of there is a <em>delete buf;</em> invokation in the <em>reset()</em>. Patch file is attached. </p> <p> Also I have managed to produce such a situation (example is attached). Below shows that the <em>gzip_decompressor</em> was constructed 4 times (1 time by default constructor and 3 times by copy constructor), but destroyed only 3 times. Destructor for object at 0x4e46b98 wasn't invoked. </p> <hr /> <p> $ valgrind ./leak_example<br /> ==18153== Memcheck, a memory error detector<br /> ==18153== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.<br /> ==18153== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info<br /> ==18153== Command: ./leak_example<br /> ==18153==<br /> <strong>gzip_decompressor has been constructed at: 0x7ff0007c0<br /> gzip_decompressor has been copy constructed from: 0x7ff0007c0 at: 0x7ff000450<br /> gzip_decompressor has been copy constructed from: 0x7ff000450 at: 0x7ff000320<br /> gzip_decompressor has been copy constructed from: 0x7ff000320 at: 0x4e46b98<br /> gzip_decompressor has been destroyed at: 0x7ff000320<br /> gzip_decompressor has been destroyed at: 0x7ff000450<br /> gzip_decompressor has been destroyed at: 0x7ff0007c0</strong><br /> ==18153==<br /> ==18153== HEAP SUMMARY:<br /> ==18153== in use at exit: 51,493 bytes in 13 blocks<br /> ==18153== total heap usage: 28 allocs, 15 frees, 69,665 bytes allocated<br /> ==18153==<br /> ==18153== LEAK SUMMARY:<br /> ==18153== <strong>definitely lost: 216 bytes in 1 blocks</strong><br /> ==18153== indirectly lost: 51,277 bytes in 12 blocks<br /> ==18153== possibly lost: 0 bytes in 0 blocks<br /> ==18153== still reachable: 0 bytes in 0 blocks<br /> ==18153== suppressed: 0 bytes in 0 blocks<br /> ==18153== Rerun with --leak-check=full to see details of leaked memory<br /> ==18153==<br /> ==18153== For counts of detected and suppressed errors, rerun with: -v<br /> ==18153== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)<br /> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4922 Trac 1.4.3 Victor Shugaev <victor.shugaev@…> Thu, 02 Dec 2010 12:26:51 GMT attachment set https://svn.boost.org/trac10/ticket/4922 https://svn.boost.org/trac10/ticket/4922 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">chain.hpp.patch</span> </li> </ul> <p> patch file for boost/iostreams/chain.hpp </p> Ticket Victor Shugaev <victor.shugaev@…> Thu, 02 Dec 2010 12:33:54 GMT attachment set https://svn.boost.org/trac10/ticket/4922 https://svn.boost.org/trac10/ticket/4922 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">leak_example.tar.gz</span> </li> </ul> <p> example </p> Ticket Daniel James Sat, 11 Jun 2011 14:20:44 GMT <link>https://svn.boost.org/trac10/ticket/4922#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4922#comment:1</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/72543" title="Iostreams: In chains, clean up properly when close throws in the ...">[72543]</a>) Iostreams: In chains, clean up properly when close throws in the destructor. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4922" title="#4922: Patches: memory leak in boost::iostreams::detail::chain_impl::~chain_impl() (closed: fixed)">#4922</a>. </p> <p> Thanks to Victor Shugaev. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Sat, 18 Jun 2011 14:34:35 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4922#comment:2 https://svn.boost.org/trac10/ticket/4922#comment:2 <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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/72668" title="Iostreams: In chains, clean up properly when close throws in the ...">[72668]</a>) Iostreams: In chains, clean up properly when close throws in the destructor. </p> <p> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4922" title="#4922: Patches: memory leak in boost::iostreams::detail::chain_impl::~chain_impl() (closed: fixed)">#4922</a>. Thanks to Victor Shugaev. Authorized by Rene. </p> Ticket