Valgrind Memcheck tool issue
-
wrote on 5 Jun 2020, 11:39 last edited by
Hi,
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
Analyzing finished."Platform details :
OS : Ubuntu, Qt version : 5.0Could anyone help me sorting out this issue. Thanks in advance.
Thanks
Nagaraj -
Hi,
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
Analyzing finished."Platform details :
OS : Ubuntu, Qt version : 5.0Could anyone help me sorting out this issue. Thanks in advance.
Thanks
Nagaraj@nagaraj_r Does this app run properly without Valgrind?
-
Hi,
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
Analyzing finished."Platform details :
OS : Ubuntu, Qt version : 5.0Could anyone help me sorting out this issue. Thanks in advance.
Thanks
Nagarajwrote on 5 Jun 2020, 13:17 last edited by JonB 6 May 2020, 13:18@nagaraj_r said in Valgrind Memcheck tool issue:
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?
-
@nagaraj_r Does this app run properly without Valgrind?
-
@nagaraj_r said in Valgrind Memcheck tool issue:
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?
-
@JonB Sorry, the exact Qt version currently using is 5.10.0 and the valgrind(3.4) which we fetched using apt-get.
wrote on 5 Jun 2020, 14:30 last edited by JonB 6 May 2020, 14:35@nagaraj_r
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)....
-
@nagaraj_r
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)....
wrote on 8 Jun 2020, 11:33 last edited by@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,
main.cpp:
#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
int *b = new int[10];
MainWindow w;
w.show();
return a.exec();
}mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
int *b = new int[10];
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}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()
-
@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,
main.cpp:
#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
int *b = new int[10];
MainWindow w;
w.show();
return a.exec();
}mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
int *b = new int[10];
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}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()
wrote on 8 Jun 2020, 11:46 last edited by JonB 6 Aug 2020, 11:46@nagaraj_r
Not sure what I can say. I usevalgrind
under Linux (Ubuntu 19.04), it hasn't "crashed" on me.I can see nothing wrong with your code per se. It looks like
valgrind
is barfing on what it regards as anIllegal instruction (core dumped)
. Somewhere down in the guts of Qt directory/regular expression/random generator (goodness knows why). It says it could bevalgrind
'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 havevalgrind-3.11.0
, I havevalgrind-3.14.0
. You could Google forvalgrind
crashes.... -
@nagaraj_r
Not sure what I can say. I usevalgrind
under Linux (Ubuntu 19.04), it hasn't "crashed" on me.I can see nothing wrong with your code per se. It looks like
valgrind
is barfing on what it regards as anIllegal instruction (core dumped)
. Somewhere down in the guts of Qt directory/regular expression/random generator (goodness knows why). It says it could bevalgrind
'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 havevalgrind-3.11.0
, I havevalgrind-3.14.0
. You could Google forvalgrind
crashes....wrote on 9 Jun 2020, 15:09 last edited by@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==
==16231==
==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**** -
@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==
==16231==
==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****wrote on 9 Jun 2020, 15:51 last edited by@nagaraj_r could you please provide the command line / options you used with Valgrind?
-
@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==
==16231==
==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****wrote on 9 Jun 2020, 16:04 last edited by JonB 6 Sept 2020, 16:04it 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.)
-
@nagaraj_r could you please provide the command line / options you used with Valgrind?
wrote on 10 Jun 2020, 06:57 last edited by@Pablo-J-Rogina exact command used is valgrind --tool=memcheck --leak-check=full exe name*
-
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.)
wrote on 10 Jun 2020, 15:38 last edited by@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.
-
@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.
wrote on 10 Jun 2020, 19:41 last edited by JonB 6 Oct 2020, 19:44@nagaraj_r
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
libdbus
in 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? -
@nagaraj_r
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
libdbus
in 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?wrote on 12 Jun 2020, 15:55 last edited by@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.
-
@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.
wrote on 12 Jun 2020, 15:57 last edited by@nagaraj_r said in Valgrind Memcheck tool issue:
now the valgrind memcheck tool correctly detecting the memory leaks.
Great! Please don't forget to mark your post as solved.
-
@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.
wrote on 12 Jun 2020, 16:20 last edited by@nagaraj_r said in Valgrind Memcheck tool issue:
@JonB libdbus has been installed as part of debian distribution
I'm sure it has, but I no idea what it is! :)
1/17