Opened 10 years ago

Closed 9 years ago

#7156 closed Bugs (fixed)

interprocess buffer streams leak memory on construction

Reported by: Jonathan Jones <jonathan.jones@…> Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:

Description

All of the boost::interprocess::*bufferstream classes leak memory on construction. Using our own, in-house leak checker, we discovered it's the following call for all classes:

basic_ios_t::init(&m_buf);

This leak only happens on Windows (seen with VS 2008 and VS 2010). We didn't see the problem with g++ 4.4.5 on Linux, nor with g++ 4.2.1 on Macintosh.

Attachments (2)

bufferstream_leak.cpp (667 bytes ) - added by Jonathan Jones <jonathan.jones@…> 10 years ago.
Very crude program which demonstrates the leak. Bufferstream types are constructed in a loop along with an int on the heap. The address of the integer advances with each iteration.
bufferstream.hpp.patch (2.9 KB ) - added by Jonathan Jones <jonathan.jones@…> 10 years ago.
Patch which seems to fix the leak.

Download all attachments as: .zip

Change History (6)

by Jonathan Jones <jonathan.jones@…>, 10 years ago

Attachment: bufferstream_leak.cpp added

Very crude program which demonstrates the leak. Bufferstream types are constructed in a loop along with an int on the heap. The address of the integer advances with each iteration.

by Jonathan Jones <jonathan.jones@…>, 10 years ago

Attachment: bufferstream.hpp.patch added

Patch which seems to fix the leak.

comment:1 by Sorin Fetche <sorin.fetche@…>, 10 years ago

The same leak appears in vectorstream family of classes, too. Tested with Boost 1.51.

comment:2 by anonymous, 9 years ago

We are also facing this issue. please fix this in the official boost release.

comment:3 by Ion Gaztañaga, 9 years ago

This is a known problem of the MSVC STL implementation. However, basic_ios::init call should be called only once, as the standard does not give any guarantee to allow calling it twice (MSVC STL leaks in this case). As pointed in http://accu.org/index.php/journals/264 we need to take of a potentially throwing custom streambuf so that basic_ios is not destroyed without being initialized. This is not a problem for bufferstream (has nothrow constructors) but it could affect vectorstream. In this second case a null streambuf will be passed to initialize basic_[i/o]stream, which will call basic_ios::init. After that, the streambuf will be replaced with vectorstream.

comment:4 by Ion Gaztañaga, 9 years ago

Resolution: fixed
Status: newclosed

(In [85555]) Fixes #7156

Note: See TracTickets for help on using tickets.