473,378 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

memory leak or mtrace()-problem?

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:~/testg++ -o memLeak meamLeak.cpp
lars@linux:~/testMALLOC_TRACE=mlog memLeak
lars@linux:~/testmtrace 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<chartest. 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<charmyString;

int main( int argc, char ** argv )
{
mtrace();

myString *test;

test = new myString;
test->append("");
delete test;

return 0;
}

Aug 2 '06 #1
4 4433
Hmm - this seems to be the bug I discovered:
https://bugzilla.redhat.com/bugzilla....cgi?id=128467

Comment 2 says:
"This is a known issue with the default allocator in gcc-3.[23].x.
These limitations have been removed for 3.4.x series."

Does that mean I need to upgrade to gcc 3.4.x if I don't want to use
the workaround?

Regards,

Lars

Aug 2 '06 #2
lars.uffm...@rwth-aachen.de schrieb:
Does that mean I need to upgrade to gcc 3.4.x if I don't want to use
the workaround?
I should really read ALL comments before posting here *g*
Comment #3 on bugzilla says "Fixed for gcc 3.4." :)

Seems case is closed... Thanks for listening to me talking to myself
*g*

Regards,

Lars

Aug 2 '06 #3
la**********@rwth-aachen.de wrote:
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:~/testg++ -o memLeak meamLeak.cpp
lars@linux:~/testMALLOC_TRACE=mlog memLeak
lars@linux:~/testmtrace 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<chartest. 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<charmyString;

int main( int argc, char ** argv )
{
mtrace();

myString *test;

test = new myString;
test->append("");
delete test;

return 0;
}
Try a loop:

#include <mcheck.h>
#include <string>

using namespace std;

typedef basic_string<charmyString;

int main( int argc, char ** argv )
{
mtrace();

myString *test;

for ( unsigned int i = 0; i < 100000000; ++i ) {
test = new myString;
test->append("");
delete test;
}
return 0;
}
Does the "leaking" compound? If not, your STL very likely uses a pooling
allocator. Those do not leak but can confuse some debugging tools.
Best

Kai-Uwe Bux
Aug 2 '06 #4
On 2 Aug 2006 12:49:22 -0700, I waved a wand and this message magically
appeared from la**********@rwth-aachen.de:
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.
Don't use mtrace() anymore. There's an excellent tool called valgrind
which works much better, and does not require you to do anything
special in your code.

I have just run valgrind on memleak.cpp and it reports no problems with
your code at all. If I comment out the line containing 'delete test',
it does report a leak.
--
http://www.munted.org.uk

Take a nap, it saves lives.
Aug 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Elbert Lev | last post by:
#When I'm running this script on my windows NT4.0 box, #every time dialog box is reopened there is memory growth 384K. #Bellow is the text I sent to Stephen Ferg (author of easygui) # I have...
1
by: Sergey Tursanov | last post by:
Hello all ! When I use code below and check my program with various memory leak detection tools I get message about memory leaks in stl_alloc.h. #include <string> int main() { std::string s...
8
by: __jakal__ | last post by:
Hello, Is there any good memory leak detection software for C++ available as a freeware... I had used purify but had to discontinue due to huge license fees... Also tried Sun workshop memory...
7
by: mosaic | last post by:
Hi, all I really interested in how to check the memory leak of a program. Your smart guys, do you have excellent ideas that could share with me? Thank you. The following is my idea: In C...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
4
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password";...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
3
by: Jack | last post by:
How to investigate a memory leak? Thanks. Jack
16
by: KS | last post by:
Hello, I have a memory leak in my application and I have identified two lines of code that cause the leak. If I comment out these lines, the program runs fine. If left uncommented, the memory...
7
by: Ragnar Agustsson | last post by:
Hi all I have been wandering about the best way to sandbox memory leaks in 3rd party libraries when using them from the .Net framework. I have a 3rd party library, written in C++, that leaks a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.