< Previous by Date Date Index Next by Date >
  Thread Index Next in Thread >

[reSIProcate] More memory leaks...


I finally got to the bottom of the next leak - it was a tough one to find.  I'm not sure if it exists or not in other OS's, and I need peoples opinions on the best fix for it - to make sure it works on all OS's.  Here is the problem:

 

The classes DataStream, iDataStream and oDataStream all end up calling basic_ios::init() twice.  This ends up leaking a pointer that is newed in ios_base::_Init() for the local (_Ploc) - at least in Windows STL it does. 

 

One solution is simple for for iDataStream and oDataStream.  The constructors currently look like this:

 

oDataStream::oDataStream(Data& str)

   : std::ostream(0),

     mStreambuf(str)

{

   init(&mStreambuf);

}

 

(same for iDataStream)

 

If we change it to be:

 

oDataStream::oDataStream(Data& str)

   : std::ostream(std::_Noinit),

     mStreambuf(str)

{

   init(&mStreambuf);

}

 

Then all is OK.  The problem is that std::iostream does not allow initialization with the std::_Noinit flag.  So then the solution that works for all would be:

DataStream::DataStream(Data& str)

   : std::iostream(&mStreambuf),

     mStreambuf(str)

{

   //init(&mStreambuf);

}

 

This builds and functions fine under VS .NET 2003 - but I'm not sure about other compilers (since mStreambuf is being constructed at the same time it questionable if it's memory address will be available).

 

I have attached the changed DataStream.cxx - can someone try and compile this on another OS?  If it doesn't work and the leak doesn't exist in other S's we can just put #IFDEFs around the fix.

 

Let me know what you guys think.

 

Thanks,

 

Scott Godin

 

PS.  Even with these last two leaks I've posted fixed there still seems to be more.  Back to the drawing board I guess.  Has anyone ever tested for memory leaks on other platforms?

 

 

 

Attachment: DataStream.cxx
Description: Binary data