PDA

View Full Version : Strange memory leak



Raadush
17th October 2012, 13:57
Hi, I have created simple qt gui application just to verify if Im doing something bad in my other application, but seems to me, that there is some kind of error in qt. I have this code:



#include "mainwindow.h"
#include <QProgressDialog>

QProgressDialog *dialog;

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
dialog = new QProgressDialog(this);
dialog->setValue(50);
dialog->show();
}

MainWindow::~MainWindow()
{
delete(dialog);
}


and when i run builtin valgrind tool on it, i get those errors on line dialog->setValue(50):

Conditional jump or move depends on uninitialised value(s)
in MainWindow::MainWindow(QWidget*) in mainwindow.cpp:10
1: __divdi3 in /usr/lib/libgcc_s-4.7.2-20120921.so.1
2: QElapsedTimer::elapsed() const in /usr/lib/libQtCore.so.4.8.2
3: QProgressDialog::setValue(int) in /usr/lib/libQtGui.so.4.8.2
4: MainWindow::MainWindow(QWidget*) in <a href="file:///home/radek/Development/LeakTest/mainwindow.cpp:10" >mainwindow.cpp:10</a>
5: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>
Uninitialised value was created by a heap allocation 1: operator new(unsigned int) in /builddir/build/BUILD/valgrind-3.7.0/coregrind/m_replacemalloc/vg_replace_malloc.c:282
2: QProgressDialog::QProgressDialog(QWidget*, QFlags&lt;Qt::WindowType&gt;) in /usr/lib/libQtGui.so.4.8.2
3: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>

Conditional jump or move depends on uninitialised value(s)
in MainWindow::MainWindow(QWidget*) in mainwindow.cpp:10
1: __divdi3 in /usr/lib/libgcc_s-4.7.2-20120921.so.1
2: QElapsedTimer::elapsed() const in /usr/lib/libQtCore.so.4.8.2
3: QProgressDialog::setValue(int) in /usr/lib/libQtGui.so.4.8.2
4: MainWindow::MainWindow(QWidget*) in <a href="file:///home/radek/Development/LeakTest/mainwindow.cpp:10" >mainwindow.cpp:10</a>
5: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>
Uninitialised value was created by a heap allocation 1: operator new(unsigned int) in /builddir/build/BUILD/valgrind-3.7.0/coregrind/m_replacemalloc/vg_replace_malloc.c:282
2: QProgressDialog::QProgressDialog(QWidget*, QFlags&lt;Qt::WindowType&gt;) in /usr/lib/libQtGui.so.4.8.2
3: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>

Conditional jump or move depends on uninitialised value(s)
in MainWindow::MainWindow(QWidget*) in mainwindow.cpp:10
1: QProgressDialog::setValue(int) in /usr/lib/libQtGui.so.4.8.2
2: MainWindow::MainWindow(QWidget*) in <a href="file:///home/radek/Development/LeakTest/mainwindow.cpp:10" >mainwindow.cpp:10</a>
3: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>
Uninitialised value was created by a heap allocation 1: operator new(unsigned int) in /builddir/build/BUILD/valgrind-3.7.0/coregrind/m_replacemalloc/vg_replace_malloc.c:282
2: QProgressDialog::QProgressDialog(QWidget*, QFlags&lt;Qt::WindowType&gt;) in /usr/lib/libQtGui.so.4.8.2
3: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>

Am I doing something wrong? Is '50' uninitialized? I don't think so. :) Or it's really some Qt issue? And I don't want to mention another 60 issues when i check 'External Errors'. Is Qt really that "leaky"?

Raadush
19th October 2012, 08:59
Anyone? It's quite annoying to debug my app when everytime I reload my application data and display progress of reload opperation, I get those errors for every setValue I have in code.

amleto
19th October 2012, 20:56
apart from using a global for no good reason, and using 'this' in a ctor.

Oh, and you delete a dialog that already has a parent -> double deletion will happen I think.

And it will get even worse if you instantiate two MainWindow...

wysota
19th October 2012, 21:22
Oh, and you delete a dialog that already has a parent -> double deletion will happen I think.
No, it's ok since delete will be called before QObject destructor kicks in.

Raadush
22nd October 2012, 07:22
No, no double deletion.

I have changed the code in such a way, that I neither use global nor 'this' in constructor:



#include "mainwindow.h"
#include <QProgressDialog>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QProgressDialog dialog;
dialog.setValue(50);
dialog.exec();
}

MainWindow::~MainWindow()
{

}


Still getting:

Conditional jump or move depends on uninitialised value(s)
in MainWindow::MainWindow(QWidget*) in mainwindow.cpp:8
1: __divdi3 in /usr/lib/libgcc_s-4.7.2-20120921.so.1
2: QElapsedTimer::elapsed() const in /usr/lib/libQtCore.so.4.8.2
3: QProgressDialog::setValue(int) in /usr/lib/libQtGui.so.4.8.2
4: MainWindow::MainWindow(QWidget*) in <a href="file:///home/radek/Development/LeakTest/mainwindow.cpp:8" >mainwindow.cpp:8</a>
5: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>
Uninitialised value was created by a heap allocation 1: operator new(unsigned int) in /builddir/build/BUILD/valgrind-3.7.0/coregrind/m_replacemalloc/vg_replace_malloc.c:282
2: QProgressDialog::QProgressDialog(QWidget*, QFlags&lt;Qt::WindowType&gt;) in /usr/lib/libQtGui.so.4.8.2
3: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>

Conditional jump or move depends on uninitialised value(s)
in MainWindow::MainWindow(QWidget*) in mainwindow.cpp:8
1: __divdi3 in /usr/lib/libgcc_s-4.7.2-20120921.so.1
2: QElapsedTimer::elapsed() const in /usr/lib/libQtCore.so.4.8.2
3: QProgressDialog::setValue(int) in /usr/lib/libQtGui.so.4.8.2
4: MainWindow::MainWindow(QWidget*) in <a href="file:///home/radek/Development/LeakTest/mainwindow.cpp:8" >mainwindow.cpp:8</a>
5: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>
Uninitialised value was created by a heap allocation 1: operator new(unsigned int) in /builddir/build/BUILD/valgrind-3.7.0/coregrind/m_replacemalloc/vg_replace_malloc.c:282
2: QProgressDialog::QProgressDialog(QWidget*, QFlags&lt;Qt::WindowType&gt;) in /usr/lib/libQtGui.so.4.8.2
3: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>

Conditional jump or move depends on uninitialised value(s)
in MainWindow::MainWindow(QWidget*) in mainwindow.cpp:8
1: QProgressDialog::setValue(int) in /usr/lib/libQtGui.so.4.8.2
2: MainWindow::MainWindow(QWidget*) in <a href="file:///home/radek/Development/LeakTest/mainwindow.cpp:8" >mainwindow.cpp:8</a>
3: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>
Uninitialised value was created by a heap allocation 1: operator new(unsigned int) in /builddir/build/BUILD/valgrind-3.7.0/coregrind/m_replacemalloc/vg_replace_malloc.c:282
2: QProgressDialog::QProgressDialog(QWidget*, QFlags&lt;Qt::WindowType&gt;) in /usr/lib/libQtGui.so.4.8.2
3: main in <a href="file:///home/radek/Development/LeakTest/main.cpp:7" >main.cpp:7</a>

wysota
22nd October 2012, 08:17
So where are the memory leaks? I can only see some warnings about branching, nothing about memory leaks.

Raadush
22nd October 2012, 09:57
Yes, I admit the topic name is wrong, cause when I started to write my question, I had leak there, but then I realized my mistake, corrected it, which caused those conditional jumps to appear, but I forgot to correct post name. My question is rather why im getting theese and can they be somehow corrected by myself? It's getting harder to find my own errors, when Im flooded with like 20-30 conditional jump errors everytime I call setValue in some place in my application. I know there is a suppression file, but I'd rather understand why Im getting those errors and try to correct them rather then simply ingore them.

wysota
22nd October 2012, 10:17
My question is rather why im getting theese and can they be somehow corrected by myself?
Are you getting any errors because of these messages? If not then I'd assume these are false positives. You won't be correcting gcc runtime anyway, right?

On the other hand launching a dialog from inside a widget constructor is a really weird thing to do...

Raadush
22nd October 2012, 11:51
Ok, thanks for your help. Im quite certain they are false positives. In my application Im not calling it from constructor, but here I wanted to reproduce the error with smallest compilable example.