PDA

View Full Version : Memory leak detection



Sid
21st August 2007, 15:36
Hi,
on linux there is valgrind to detect memory leak.
But what tool (free/open source) can i use to detect memory leak on the open source version of QT4.3 with the mingw compiler.

I have a C application (command line) that fireup at some point a QT4 dll interface.
All the whole application (exe and dll) is compiled with mingw-gcc.
It's a bit like VLC which have the QT4 interface as a DLL.

My point here is to check for memory leak in the QT4 part.
I've google so far, and i found one website :
Wu Yongwei’s Programming Page (http://wyw.dcweb.cn/)
But it seems not be working fine on QT4 objects.

I know there is a tool called Purify from IBM which is not free and works better with Visual C++.
I want to stick with mingw.

Anyone can help here :)

Thanks

jpn
24th August 2007, 11:54
I've google so far, and i found one website :
Wu Yongwei’s Programming Page (http://wyw.dcweb.cn/)
But it seems not be working fine on QT4 objects.
What kind of problems did you encounter? I gave it a quick try and it seems to detect at least basic and obvious leaks just fine. :)

Darhuuk
10th January 2008, 12:07
First of all, sorry for digging up such an old thread, but I figured it was better to continue this one than to make a new one.

I'm trying to implement memory leak detection in my debug exe and for that I'm using the memory leak detector linked to in the original poster's post. However, I don't get any ouput. I'm guessing this is because my application is a GUI and I have no console window.

I did some simple tests, like adding a "cout << "Test";" line to my app and if I run it like this from the command prompt: "testapp.exe > output.txt", it works just fine, console output gets written to output.txt upon exit. So, after thinking about complaining here for help I dug a little deeper ;).

First, I tried changing line 149 of debug_new.h to:

: _M_file(file), _M_line(line) { freopen("file_of_choice.txt", "w", new_output_fp); }

But, for some reason that didn't quite work. In case anyone knows why, feel free to let me know. I even added a cout test line in the constructor, but it doesn't seem to do anything, pretty weird.

The simple solution is to edit line 281 of debug_new.cpp and change "stderr" to "stdout", so you can redirect the output to a file by simple calling your program from console with program.exe > outputfile.txt.

If anyone knows a more graceful solution, let me know.

Ok, this is newbie stuff, but still, it might save someone some time.

jpn
10th January 2008, 12:16
Enable console by adding

QT += console
to .pro file and then re-build the application.

Darhuuk
10th January 2008, 12:22
Hm, that doesn't seem to work. When I add "console" I get an "undefined reference to 'WinMain@16'" error from libmingw32.a(main.o). Removing "windows" from CONFIG doesn't help either.

jpn
10th January 2008, 12:36
Just rebuild the application:


> make clean
> make

Darhuuk
10th January 2008, 12:43
Ah, ok, thanks, didn't know a rebuild required a make clean. It works now.

falconium
4th May 2011, 17:29
I want to do the same, but it only shows the address of variable in memory, not the line of code:

Leaked object at 003E6D80 (size 4, 004013CA)
Leaked object at 003E6DE0 (size 10, 004013DA)
*** 2 leaks found

I understand there is program called addr2line for linux, but I'm on windows platform. How could I translate it?

Thanks!

Update: OK, i found it mingw32 folder. How should I use it on windows on executables?
I have tried this addr2line -e <app.exe> 00415B82 and without address, but no meaningful output, just these:

??:0

??:0

??:0

??:0

??:0

falconium
4th May 2011, 23:38
OK, I should have used the debug version of the executable.... :rolleyes: