L
lars.uffmann
I just reduced a nasty and hard to pin-down memory leak (according to
mtrace() under SuSE 9.3 to a very simple example file and would like to
know what the error is about, and whether it maybe is a bug in the
basic_string-template, or a bug / problem with mtrace, or something
else - and if other people can reproduce it - possibly under
non-SuSE-distributions.
Using g++ to compile memLeak.cpp with gnu c compiler 3.3.5, the
following happens:
-----------
lars@linux:~/test> g++ -o memLeak meamLeak.cpp
lars@linux:~/test> MALLOC_TRACE=mlog memLeak
lars@linux:~/test> mtrace memLeak mlog
Memory not freed:
-----------------
Address Size Caller
0x0804a388 0x280 at 0x400d90ee
lars@linux:~/test>
----------
File memLeak.cpp is attached.
Apparently causing the problem is code line 15, where an empty string
is appended to the basic_string<char> test. I have tried test->clear()
to unallocate the memory used, but it didn't change the result (memory
leak still occurs). I have no idea how to unallocate the memory. Any
input?
Regards,
Lars
File memLeak.cpp:
-----------------------
#include <mcheck.h>
#include <string>
using namespace std;
typedef basic_string<char> myString;
int main( int argc, char ** argv )
{
mtrace();
myString *test;
test = new myString;
test->append("");
delete test;
return 0;
}
mtrace() under SuSE 9.3 to a very simple example file and would like to
know what the error is about, and whether it maybe is a bug in the
basic_string-template, or a bug / problem with mtrace, or something
else - and if other people can reproduce it - possibly under
non-SuSE-distributions.
Using g++ to compile memLeak.cpp with gnu c compiler 3.3.5, the
following happens:
-----------
lars@linux:~/test> g++ -o memLeak meamLeak.cpp
lars@linux:~/test> MALLOC_TRACE=mlog memLeak
lars@linux:~/test> mtrace memLeak mlog
Memory not freed:
-----------------
Address Size Caller
0x0804a388 0x280 at 0x400d90ee
lars@linux:~/test>
----------
File memLeak.cpp is attached.
Apparently causing the problem is code line 15, where an empty string
is appended to the basic_string<char> test. I have tried test->clear()
to unallocate the memory used, but it didn't change the result (memory
leak still occurs). I have no idea how to unallocate the memory. Any
input?
Regards,
Lars
File memLeak.cpp:
-----------------------
#include <mcheck.h>
#include <string>
using namespace std;
typedef basic_string<char> myString;
int main( int argc, char ** argv )
{
mtrace();
myString *test;
test = new myString;
test->append("");
delete test;
return 0;
}