Results 1 to 9 of 9

Thread: Strange memory leak

  1. #1
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Question Strange memory leak

    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:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QProgressDialog>
    3.  
    4.  
    5. MainWindow::MainWindow(QWidget *parent)
    6. : QMainWindow(parent)
    7. {
    8. dialog = new QProgressDialog(this);
    9. dialog->setValue(50);
    10. dialog->show();
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete(dialog);
    16. }
    To copy to clipboard, switch view to plain text mode 

    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"?

  2. #2
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Strange memory leak

    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.

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Strange memory leak

    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...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strange memory leak

    Quote Originally Posted by amleto View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Strange memory leak

    No, no double deletion.

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

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QProgressDialog>
    3.  
    4. MainWindow::MainWindow(QWidget *parent)
    5. : QMainWindow(parent)
    6. {
    7. dialog.setValue(50);
    8. dialog.exec();
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    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>

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strange memory leak

    So where are the memory leaks? I can only see some warnings about branching, nothing about memory leaks.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Strange memory leak

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strange memory leak

    Quote Originally Posted by Raadush View Post
    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...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    Raadush (22nd October 2012)

  10. #9
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Strange memory leak

    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.

Similar Threads

  1. memory leak - where?
    By Tomasz in forum Newbie
    Replies: 36
    Last Post: 5th September 2010, 23:47
  2. Qt dll + memory leak
    By Fastman in forum Qt Programming
    Replies: 3
    Last Post: 2nd August 2009, 13:28
  3. memory leak
    By mattia in forum Newbie
    Replies: 18
    Last Post: 16th January 2008, 10:22
  4. Memory leak?
    By Enygma in forum Qt Programming
    Replies: 10
    Last Post: 4th September 2007, 16:24
  5. Memory leak
    By zlatko in forum Qt Programming
    Replies: 8
    Last Post: 28th March 2006, 19:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.