Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Valgrind Memcheck tool issue
I am trying to analyze the memory leak issue of our Qt application using Valgrind Memcheck tool integrated into the Qt creator IDE.
Just to confirm whether memcheck correctly detects memory leak, created simple Qt application which just displays the main window, I explicitly introduced memory leak just before a.exec() call by creating dynamic memory without deleting it.
when I click Start application in Memcheck toolbar, it shows the below error message in the application output window and did not detect the leak which I manually introduced.
"The program has unexpectedly finished.
Process exited with return value Process crashed
Platform details :
OS : Ubuntu, Qt version : 5.0
Could anyone help me sorting out this issue. Thanks in advance.
@nagaraj_r Does this app run properly without Valgrind?
Qt version : 5.0
Additional to @jsulm (it's vital you reply to him), do you really need to be using as old a Qt version as 5.0?
And, further, the Qt Creator is only an interface to your own valgrind which you fetched/installed, how old is that?
@jsulm Yes, it is running fine - no error msg displayed, without memcheck analyzer.
@JonB Sorry, the exact Qt version currently using is 5.10.0 and the valgrind(3.4) which we fetched using apt-get.
I can only say I am Ubuntu 19.04, Qt 5.12.2 & valgrind 3.14.0, and all works fine when I use it.
You could (i.e should) test your app under valgrind outside of Qt Creator to see if you can eliminate that from being the issue.
If your code is that simple/small, we wouldn't mind seeing your source just to make sure nothing amiss (valgrind could show up problems you don't see without it)....
@JonB I tried to run the valgrind memcheck tool outside of Qt creator IDE in command prompt, but still it couldn't find the memory leak in the program.
Sample code is as below,
int main(int argc, char *argv)
QApplication a(argc, argv);
int *b = new int;
MainWindow::MainWindow(QWidget *parent) :
int *b = new int;
output of the memcheck tool is as below, when executed from command prompt, where it could not list the leaked memory of 40 bytes each in main() and MainWindow()
Not sure what I can say. I use
valgrindunder Linux (Ubuntu 19.04), it hasn't "crashed" on me.
I can see nothing wrong with your code per se. It looks like
valgrindis barfing on what it regards as an
Illegal instruction (core dumped). Somewhere down in the guts of Qt directory/regular expression/random generator (goodness knows why). It says it could be
valgrind's fault and you have to report it!
Try on a still simpler program (e.g. just a
main()). Not that it will help you much. You have
valgrind-3.11.0, I have
valgrind-3.14.0. You could Google for
@JonB Thanks for the response. After upgrading to Valgrind version 3.14.0, tried to analyze the same simple qt application(source for which shared earlier thread), it hasn't crashed. this time.
But it shows lot of false positive memory leak issues in gcc libraries and Qt libraries which we don't want to report.
Could you please let me know, how to suppress these errors.
6,773 (232 direct, 6,541 indirect) bytes in 1 blocks are definitely lost in loss record 7,739 of 7,769
==16231== at 0x4C2FF6C: calloc (vg_replace_malloc.c:752)
==16231== by 0xE606DFF: ??? (in /lib/x86_64-linux-gnu/libdbus-1.so.3.14.6)
==16231== by 0xE61120E: ??? (in /lib/x86_64-linux-gnu/libdbus-1.so.3.14.6)
==16231== by 0xE6116E2: ??? (in /lib/x86_64-linux-gnu/libdbus-1.so.3.14.6)
==16231== by 0xE605179: ??? (in /lib/x86_64-linux-gnu/libdbus-1.so.3.14.6)
==16231== by 0xE5EF80E: ??? (in /lib/x86_64-linux-gnu/libdbus-1.so.3.14.6)
==16231== by 0xDD2D137: ??? (in /opt/Qt5.10.0/5.10.0/gcc_64/lib/libQt5DBus.so.5.10.0)
==16231== by 0x591EB20: QObject::event(QEvent) (in /opt/Qt5.10.0/5.10.0/gcc_64/lib/libQt5Core.so.5.10.0)
==16231== Memcheck, a memory error detector
==16231== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16231== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==16231== Command: /home/dinesh/build-test-Desktop_Qt_5_10_0_GCC_64bit-Debug/test
==16231== Parent PID: 2323
==16231== HEAP SUMMARY:
==16231== in use at exit: 1,563,805 bytes in 19,588 blocks
==16231== total heap usage: 145,872 allocs, 126,284 frees, 88,031,708 bytes allocated
==16231== by 0x58F29E2: QCoreApplication::notifyInternal2(QObject, QEvent) (in /opt/Qt5.10.0/5.10.0/gcc_64/lib/libQt5Core.so.5.10.0)
==16231== by 0x58F548A: QCoreApplicationPrivate::sendPostedEvents(QObject, int, QThreadData*) (in /opt/Qt5.10.0/5.10.0/gcc_64/lib/libQt5Core.so.5.10.0)
==16231== by 0x5947562: ??? (in /opt/Qt5.10.0/5.10.0/gcc_64/lib/libQt5Core.so.5.10.0)
==16231== by 0x9F42196: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2)
==16231== LEAK SUMMARY:
==16231== definitely lost: 840 bytes in 6 blocks
==16231== indirectly lost: 12,986 bytes in 78 blocks
==16231== possibly lost: 3,752 bytes in 33 blocks
==16231== still reachable: 1,464,123 bytes in 18,800 blocks
==16231== of which reachable via heuristic:
==16231== length64 : 4,904 bytes in 80 blocks
==16231== newarray : 2,096 bytes in 51 blocks****
Pablo J. Rogina last edited by
@nagaraj_r could you please provide the command line / options you used with Valgrind?
it hasn't crashed. this time.
That's an important start!
All I know is: when I run Analyze > Valgrind Memory Analyzer from Creator I accept the default filter on the Memcheck window which is having External Errors unchecked. That removes 32 warnings about internal Qt stuff, and I don't get any false positives left. (I do unfortunately get "false negatives", in that valgrind can miss some leaks. but that's another matter.)
@Pablo-J-Rogina exact command used is valgrind --tool=memcheck --leak-check=full exe name*
@JonB Thank you for your response. I tried to suppress the errors reported from the Qt libraries using the suppression file, although some false positive errors got reduced now, but it is still not completely resolved. If you have ever used this suppression option, please provide the details.
Nope, as I said, no suppression, no tailoring, vanilla out-of-the-box. It arrives with the 32 Qt/C++ library errors already filtered out from not having External Errors checked (in Creator), I changed nothing, and in that state I get no further false positives.
I note the leak you show has
libdbusin it. I wouldn't know what a "dbus" was even if I met one. Does that indicate you are running in rather different than I am?
@JonB libdbus has been installed as part of debian distribution of Ubuntu version.
I have created supression file by using --gen-suppressions= all option, with this suppression file, and using --suppressions=supp filename, now the valgrind memcheck tool correctly detecting the memory leaks.
Thank you for your support.
Pablo J. Rogina last edited by
now the valgrind memcheck tool correctly detecting the memory leaks.
Great! Please don't forget to mark your post as solved.
JonB last edited by
@JonB libdbus has been installed as part of debian distribution
I'm sure it has, but I no idea what it is! :)