This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

std::stringstream definitely leaks memory (was: Memory leak in ios.cc:326)


Did someone open a PR for this?

It is a very serious bug / regression, not even related
to threads.  ostringstream simply leaks 76 bytes per
creation/destruction.

I must add that the fact that this allocation (via
std::allocator!) is done at all gives me major headaches;
As you know I maintain a C++ debugging library for
the GNU compiler (doesn't work with another compiler),
that support ostream debugging output.

The problem that the above allocation gives me is that
when anything is allocation memory via std::allocator,
then a lock is set before 'new' is called, causing subsequent
calls to std::allocator to dead lock.  In other words,
I can't anymore create a stringstream<my_allocator> now
during my debug output because that suddenly (always)
allocates 73 bytes via std::allocator!  It did NOT do
that with g++-3.2 and the libstdc++ version that belongs
to that release.

I hope somehow that while fixing the above memory leak,
it will turn out to be possible not to allocate memory
at all via std::allocator anymore...

-- 
Carlo Wood <carlo at alinoe dot com>


---------------
Test program:

~/c++/tests>cat ostringstream.cc
#include "sys.h"
#include <iostream>
#include <sstream>
#include "debug.h"

int main(void)
{
  std::ios::sync_with_stdio(false);
  Debug( check_configuration() );

#if CWDEBUG_ALLOC
  // Remove all current (pre- main) allocations from the Allocated Memory Overview.
  libcw::debug::make_all_allocations_invisible_except(NULL);
#endif

  ForAllDebugChannels( while (!debugChannel.is_on()) debugChannel.on() );
  Debug( libcw_do.on() );
  Debug( libcw_do.set_ostream(&std::cout) );
  Debug( list_channels_on(libcw_do) );

  // *** START OF TEST CODE ***
  for (int i = 0; i < 10; ++i)
  {
    std::ostringstream os;
    os << "Hello world\n";
    std::cout << os.str();
  }
  // *** END OF TEST CODE ***

  Debug( list_allocations_on(libcw_do) );

  return 0;
}

~/c++/tests>g++-cvs-3.3 -g -DCWDEBUG -I. ostringstream.cc -lcwd
~/c++/tests>a.out
BFD     : Enabled
DEBUG   : Enabled
MALLOC  : Enabled
NOTICE  : Enabled
SYSTEM  : Enabled
WARNING : Enabled
MALLOC  : operator new (size = 60) = 0x8055870
MALLOC  : operator new (size = 16) = 0x80b2260
MALLOC  : operator new (size = 1136) = <unfinished>
BFD     :     address 0x400e3e5c corresponds to stl_alloc.h:388
MALLOC  : <continued> 0x8118dc0
Hello world
MALLOC  : delete 0x8118dc0          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : operator new (size = 60) = 0x8104f98
MALLOC  : operator new (size = 16) = 0x81051f8
MALLOC  : operator new (size = 1136) = 0x8118dc0
Hello world
MALLOC  : delete 0x8118dc0          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : operator new (size = 60) = 0x8117cb8
MALLOC  : operator new (size = 16) = 0x8117e68
MALLOC  : operator new (size = 1136) = 0x8118dc0
Hello world
MALLOC  : delete 0x8118dc0          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : operator new (size = 60) = 0x807e790
MALLOC  : operator new (size = 16) = 0x81181d8
MALLOC  : operator new (size = 1136) = 0x8118dc0
Hello world
MALLOC  : delete 0x8118dc0          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : operator new (size = 60) = 0x80a27e0
MALLOC  : operator new (size = 16) = 0x8118de0
MALLOC  : operator new (size = 1136) = 0x80a2d78
Hello world
MALLOC  : delete 0x80a2d78          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : operator new (size = 60) = 0x8118a90
MALLOC  : operator new (size = 16) = 0x8118ba0
MALLOC  : operator new (size = 1136) = 0x80a2d78
Hello world
MALLOC  : delete 0x80a2d78          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : operator new (size = 60) = 0x8118d60
MALLOC  : operator new (size = 16) = 0x8118db0
MALLOC  : operator new (size = 1136) = 0x80a3248
Hello world
MALLOC  : delete 0x80a3248          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : operator new (size = 60) = 0x80a2b08
MALLOC  : operator new (size = 16) = 0x80a2c18
MALLOC  : operator new (size = 1136) = 0x80a3248
Hello world
MALLOC  : delete 0x80a3248          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : operator new (size = 60) = 0x80a32b8
MALLOC  : operator new (size = 16) = 0x80a2ea8
MALLOC  : operator new (size = 1136) = 0x80a37d8
Hello world
MALLOC  : delete 0x80a37d8          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : operator new (size = 60) = 0x80a3068
MALLOC  : operator new (size = 16) = 0x80a3178
MALLOC  : operator new (size = 1248) = 0x80a3cc8
MALLOC  : operator new (size = 1136) = 0x8085d48
Hello world
MALLOC  : delete 0x8085d48          stl_alloc.h:388  <unknown type>; (sz = 1136)  
MALLOC  : Allocated memory: 2008 bytes in 21 blocks:
BFD     : address 0x400ddffa corresponds to stl_alloc.h:507
          0x80a3cc8          stl_alloc.h:507  <unknown type>; (sz = 1248) 
BFD     : address 0x400aacf5 corresponds to ios.cc:326
          0x80a3178               ios.cc:326  <unknown type>; (sz = 16) 
BFD     : address 0x400a8db2 corresponds to memory:183
          0x80a3068               memory:183  <unknown type>; (sz = 60) 
          0x80a2ea8               ios.cc:326  <unknown type>; (sz = 16) 
          0x80a32b8               memory:183  <unknown type>; (sz = 60) 
          0x80a2c18               ios.cc:326  <unknown type>; (sz = 16) 
          0x80a2b08               memory:183  <unknown type>; (sz = 60) 
          0x8118db0               ios.cc:326  <unknown type>; (sz = 16) 
          0x8118d60               memory:183  <unknown type>; (sz = 60) 
          0x8118ba0               ios.cc:326  <unknown type>; (sz = 16) 
          0x8118a90               memory:183  <unknown type>; (sz = 60) 
          0x8118de0               ios.cc:326  <unknown type>; (sz = 16) 
          0x80a27e0               memory:183  <unknown type>; (sz = 60) 
          0x81181d8               ios.cc:326  <unknown type>; (sz = 16) 
          0x807e790               memory:183  <unknown type>; (sz = 60) 
          0x8117e68               ios.cc:326  <unknown type>; (sz = 16) 
          0x8117cb8               memory:183  <unknown type>; (sz = 60) 
          0x81051f8               ios.cc:326  <unknown type>; (sz = 16) 
          0x8104f98               memory:183  <unknown type>; (sz = 60) 
          0x80b2260               ios.cc:326  <unknown type>; (sz = 16) 
          0x8055870               memory:183  <unknown type>; (sz = 60) 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]