Modify

Ticket #4922 (closed Patches: fixed)

Opened 3 years ago

Last modified 3 years ago

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

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

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

Change History

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

patch file for boost/iostreams/chain.hpp

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

example

comment:1 Changed 3 years ago by danieljames

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

Thanks to Victor Shugaev.

comment:2 Changed 3 years ago by danieljames

  • Status changed from new to closed
  • Resolution set to fixed

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

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.