Opened 12 years ago
Closed 11 years ago
#4922 closed Patches (fixed)
memory leak in boost::iostreams::detail::chain_impl::~chain_impl()
Reported by: | Owned by: | Jonathan Turkanis | |
---|---|---|---|
Milestone: | To Be Determined | Component: | iostreams |
Version: | Boost 1.45.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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
==18153== Memcheck, a memory error detector
==18153== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==18153== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==18153== Command: ./leak_example
==18153==
gzip_decompressor has been constructed at: 0x7ff0007c0
gzip_decompressor has been copy constructed from: 0x7ff0007c0 at: 0x7ff000450
gzip_decompressor has been copy constructed from: 0x7ff000450 at: 0x7ff000320
gzip_decompressor has been copy constructed from: 0x7ff000320 at: 0x4e46b98
gzip_decompressor has been destroyed at: 0x7ff000320
gzip_decompressor has been destroyed at: 0x7ff000450
gzip_decompressor has been destroyed at: 0x7ff0007c0
==18153==
==18153== HEAP SUMMARY:
==18153== in use at exit: 51,493 bytes in 13 blocks
==18153== total heap usage: 28 allocs, 15 frees, 69,665 bytes allocated
==18153==
==18153== LEAK SUMMARY:
==18153== definitely lost: 216 bytes in 1 blocks
==18153== indirectly lost: 51,277 bytes in 12 blocks
==18153== possibly lost: 0 bytes in 0 blocks
==18153== still reachable: 0 bytes in 0 blocks
==18153== suppressed: 0 bytes in 0 blocks
==18153== Rerun with --leak-check=full to see details of leaked memory
==18153==
==18153== For counts of detected and suppressed errors, rerun with: -v
==18153== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
Attachments (2)
Change History (4)
by , 12 years ago
Attachment: | chain.hpp.patch added |
---|
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
patch file for boost/iostreams/chain.hpp