| re: Strstreambuf memory leak
On Fri, 16 Jul 2004 23:21:42 -0700, Rajwarya wrote:
[color=blue]
> No the line rdbuf->freeze(0) is getting excecuted.[/color]
I will be very picky here and say that you can't be sure that it's
called every time it is needed.
#include <strstream>
void bar()
{
/* ... */
}
int main()
{
ostrstream out;
out << 42;
out.str();
bar(); // If bar throws, the following line is not executed
out.freeze(false);
out.str(); // BUG: need to call freeze again; but forgot!
}
At a previous job, I caught more than 50 memory leaks related to the
use of ostrstream, just by grepping for 'ostrstream' and examining
code. Most of them were related to missing 'freeze' calls.
I replaced all of them with ostringstreams but then some operations
became very slow: 10 seconds instead of 1 second! :(
Also, I am not sure whether you are supposed to call freeze on rdbuf
or ostrstream.
If Purify's output is not helpful enough try other tools like the free
valgrind on Linux.
Ali |