Modify

Opened 7 years ago

Closed 6 years ago

#4922 closed Patches (fixed)

memory leak in boost::iostreams::detail::chain_impl::~chain_impl()

Reported by: victor.shugaev@… 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)

chain.hpp.patch (176 bytes) - added by Victor Shugaev <victor.shugaev@…> 7 years ago.
patch file for boost/iostreams/chain.hpp
leak_example.tar.gz (2.1 KB) - added by Victor Shugaev <victor.shugaev@…> 7 years ago.
example

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by Victor Shugaev <victor.shugaev@…>

Attachment: chain.hpp.patch added

patch file for boost/iostreams/chain.hpp

Changed 7 years ago by Victor Shugaev <victor.shugaev@…>

Attachment: leak_example.tar.gz added

example

comment:1 Changed 6 years ago by Daniel James

(In [72543]) Iostreams: In chains, clean up properly when close throws in the destructor. Refs #4922.

Thanks to Victor Shugaev.

comment:2 Changed 6 years ago by Daniel James

Resolution: fixed
Status: newclosed

(In [72668]) Iostreams: In chains, clean up properly when close throws in the destructor.

Fixes #4922. Thanks to Victor Shugaev. Authorized by Rene.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonathan Turkanis.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.