We are experiencing a memory leak with "stringstream::str()" and I am not sure if this is a leak in our STL implementation or if we are suppossed to manage the memory returned. The call to "stringstream::str()" below leaks:
while ( true )
ss << "Hello World!" << ends;
string s( ss.str() );
If we remove the call to "stringstream::str()" or assign the return value to a "char*" pointer and then call "delete" on it, the leak goes away.
What I don't understand is, doesn't "stringstream::str()" work like "string::c_str()", where it's just giving you a pointer to the internal memory it manages? If not, then what is the "correct" way of handling the returned memory? Should I put it into an "auto_ptr"?
This leaks on using the Sun C++ 4.2 compiler on Solaris 2.6. The STL implementation is provided by ObjectSpace. I was not able to reproduce the leak using VC++ 6.0.