[Boost-bugs] [Boost C++ Libraries] #4922: memory leak in boost::iostreams::detail::chain_impl::~chain_impl()

Subject: [Boost-bugs] [Boost C++ Libraries] #4922: memory leak in boost::iostreams::detail::chain_impl::~chain_impl()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-12-02 12:25:38


#4922: memory leak in boost::iostreams::detail::chain_impl::~chain_impl()
--------------------------------------+-------------------------------------
 Reporter: victor.shugaev@… | Owner: turkanis
     Type: Patches | Status: new
Milestone: To Be Determined | Component: iostreams
  Version: Boost 1.45.0 | Severity: Problem
 Keywords: |
--------------------------------------+-------------------------------------
 It appears that there are some cases when the ''chain_impl::close()''
 ('''boost/iostreams/chain.hpp''') throws an exception. If it is invoked
 from
 {{{
 ~chain_impl() { try { close(); reset(); } catch (...) { } }
 }}}
 the following ''reset()'' method won't be invoked and it results in memory
 leak because of there is a ''delete buf;'' invokation in the ''reset()''.
 Patch file is attached.

 Also I have managed to produce such a situation (example is attached).
 Below shows that the ''gzip_decompressor'' 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.

 ----
 $ 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]]
 '''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'''[[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== '''definitely lost: 216 bytes in 1 blocks'''[[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]]

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4922>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC