You are not logged in.

#1 2010-12-28 17:54:26

lucak3
Member
From: Italy
Registered: 2010-01-23
Posts: 72

Qt simple example crash-on-exit

It's my first time toying with Qt, so please consider not being too harsh on my mistakes.
I wrote this piece of code just to figure out how the build mechanisms worked:

#include <QtGui>
int main(int argv, char **args)
{
    QApplication app(argv, args);
    QVBoxLayout layout;
    QWidget window;
    window.setLayout(&layout);
    window.show();
    return app.exec();
}

Saved as app.cpp in qttest2 directory in my home.
The I issued:

qmake -project; qmake; make

All went OK, then, testing the app, I got this backtrace on console:

$ ./qttest2 
*** glibc detected *** ./qttest2: free(): invalid pointer: 0xaf871774 ***
======= Backtrace: =========
/lib/libc.so.6(+0x6c301)[0xa6c0d301]
/lib/libc.so.6(+0x6dc4b)[0xa6c0ec4b]
/lib/libc.so.6(cfree+0x6d)[0xa6c11dfd]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xa6db7281]
/usr/lib/libQtGui.so.4(_ZN11QVBoxLayoutD0Ev+0x2a)[0xa6f3348a]
/usr/lib/libQtGui.so.4(_ZN7QWidgetD2Ev+0x153)[0xa6f772c3]
./qttest2[0x8048844]
/lib/libc.so.6(__libc_start_main+0xe6)[0xa6bb7c76]
./qttest2[0x8048711]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:04 655619     /home/luca/lavori/qttest2/qttest2
08049000-0804a000 rw-p 00000000 08:04 655619     /home/luca/lavori/qttest2/qttest2
09bb0000-09cad000 rw-p 00000000 00:00 0          [heap]
a4e00000-a4e21000 rw-p 00000000 00:00 0 
a4e21000-a4f00000 ---p 00000000 00:00 0 
a4fe3000-a4fed000 r-xp 00000000 08:04 1623       /lib/libnss_files-2.12.1.so
a4fed000-a4fee000 r--p 00009000 08:04 1623       /lib/libnss_files-2.12.1.so
a4fee000-a4fef000 rw-p 0000a000 08:04 1623       /lib/libnss_files-2.12.1.so
a4fef000-a4ffc000 r-xp 00000000 08:04 7447       /usr/lib/liboxygenstyle.so.4.5.0
a4ffc000-a4ffd000 rw-p 0000d000 08:04 7447       /usr/lib/liboxygenstyle.so.4.5.0
a4ffd000-a5086000 r-xp 00000000 08:04 52943      /usr/lib/kde4/plugins/styles/oxygen.so
a5086000-a508a000 rw-p 00088000 08:04 52943      /usr/lib/kde4/plugins/styles/oxygen.so
a508a000-a50c5000 r-xp 00000000 08:04 5654       /usr/lib/libdbus-1.so.3.5.3
a50c5000-a50c6000 r--p 0003b000 08:04 5654       /usr/lib/libdbus-1.so.3.5.3
a50c6000-a50c7000 rw-p 0003c000 08:04 5654       /usr/lib/libdbus-1.so.3.5.3
a50c7000-a522a000 r-xp 00000000 08:04 84087      /usr/lib/libcrypto.so.1.0.0
a522a000-a523e000 rw-p 00162000 08:04 84087      /usr/lib/libcrypto.so.1.0.0
a523e000-a5241000 rw-p 00000000 00:00 0 
a5241000-a528e000 r-xp 00000000 08:04 82299      /usr/lib/libssl.so.1.0.0
a528e000-a5292000 rw-p 0004d000 08:04 82299      /usr/lib/libssl.so.1.0.0
a5292000-a53b3000 r-xp 00000000 08:04 230        /usr/lib/libxml2.so.2.7.8
a53b3000-a53b8000 rw-p 00121000 08:04 230        /usr/lib/libxml2.so.2.7.8
a53b8000-a53b9000 rw-p 00000000 00:00 0 
a53b9000-a53f3000 r-xp 00000000 08:04 51628      /usr/lib/libstreams.so.0.7.2
a53f3000-a53f4000 rw-p 0003a000 08:04 51628      /usr/lib/libstreams.so.0.7.2
a53f4000-a5448000 r-xp 00000000 08:04 6145       /usr/lib/libsopranoclient.so.1.2.0
a5448000-a544a000 rw-p 00053000 08:04 6145       /usr/lib/libsopranoclient.so.1.2.0
a544a000-a5584000 r-xp 00000000 08:04 6136       /usr/lib/libsoprano.so.4.3.0
a5584000-a5588000 rw-p 00139000 08:04 6136       /usr/lib/libsoprano.so.4.3.0
a5588000-a55a8000 r-xp 00000000 08:04 16734      /usr/lib/liblzma.so.5.0.0
a55a8000-a55a9000 rw-p 00020000 08:04 16734      /usr/lib/liblzma.so.5.0.0
a55a9000-a55b8000 r-xp 00000000 08:04 1949       /lib/libbz2.so.1.0.6
a55b8000-a55b9000 rw-p 0000f000 08:04 1949       /lib/libbz2.so.1.0.6
a55b9000-a55bd000 r-xp 00000000 08:04 19382      /usr/lib/libXtst.so.6.1.0
a55bd000-a55be000 rw-p 00003000 08:04 19382      /usr/lib/libXtst.so.6.1.0
a55be000-a55eb000 r-xp 00000000 08:04 38896      /usr/lib/libdbusmenu-qt.so.2.3.6
a55eb000-a55ec000 rw-p 0002d000 08:04 38896      /usr/lib/libdbusmenu-qt.so.2.3.6
a55ec000-a5664000 r-xp 00000000 08:04 10896      /usr/lib/libQtDBus.so.4.7.1
a5664000-a5665000 rw-p 00078000 08:04 10896      /usr/lib/libQtDBus.so.4.7.1
a5665000-a56b7000 r-xp 00000000 08:04 14090      /usr/lib/libQtSvg.so.4.7.1
a56b7000-a56b9000 rw-p 00051000 08:04 14090      /usr/lib/libQtSvg.so.4.7.1
a56b9000-a56bd000 r-xp 00000000 08:04 2803       /lib/libattr.so.1.1.0
a56bd000-a56be000 rw-p 00003000 08:04 2803       /lib/libattr.so.1.1.0
a56be000-a56c4000 r-xp 00000000 08:04 2751       /lib/libacl.so.1.1.0
a56c4000-a56c5000 rw-p 00005000 08:04 2751       /lib/libacl.so.1.1.0
a56c5000-a5703000 r-xp 00000000 08:04 14109      /usr/lib/libQtXml.so.4.7.1
a5703000-a5705000 rw-p 0003d000 08:04 14109      /usr/lib/libQtXml.so.4.7.1
a5705000-a5816000 r-xp 00000000 08:04 14177      /usr/lib/libQtNetwork.so.4.7.1
a5816000-a581a000 rw-p 00110000 08:04 14177      /usr/lib/libQtNetwork.so.4.7.1
a581a000-a588a000 r-xp 00000000 08:04 23679      /usr/lib/libsolid.so.4.5.0
a588a000-a5892000 rw-p 00070000 08:04 23679      /usr/lib/libsolid.so.4.5.0
a5892000-a5915000 r-xp 00000000 08:04 51631      /usr/lib/libstreamanalyzer.so.0.7.2
a5915000-a5917000 rw-p 00083000 08:04 51631      /usr/lib/libstreamanalyzer.so.0.7.2
a5917000-a599c000 r-xp 00000000 08:04 23700      /usr/lib/libnepomuk.so.4.5.0
a599c000-a599e000 rw-p 00085000 08:04 23700      /usr/lib/libnepomuk.so.4.5.0
a599e000-a5bf3000 r-xp 00000000 08:04 23653      /usr/lib/libkdecore.so.5.5.0
a5bf3000-a5bff000 rw-p 00255000 08:04 23653      /usr/lib/libkdecore.so.5.5.0
a5bff000-a5f6f000 r-xp 00000000 08:04 23868      /usr/lib/libkdeui.so.5.5.0
a5f6f000-a5f89000 rw-p 0036f000 08:04 23868      /usr/lib/libkdeui.so.5.5.0
a5f89000-a5f8a000 rw-p 00000000 00:00 0 
a5f8a000-a61ca000 r-xp 00000000 08:04 27426      /usr/lib/libkio.so.5.5.0
a61ca000-a61d6000 rw-p 0023f000 08:04 27426      /usr/lib/libkio.so.5.5.0
a61d6000-a61d7000 rw-p 00000000 00:00 0 
a61fe000-a61ff000 rw-s 00000000 00:04 41975925   /SYSV00000000 (deleted)
a61ff000-a6207000 r-xp 00000000 08:04 52944      /usr/lib/kde4/plugins/gui_platform/libkde.so
a6207000-a6208000 rw-p 00007000 08:04 52944      /usr/lib/kde4/plugins/gui_platform/libkde.so
a6208000-a620e000 r-xp 00000000 08:04 20298      /usr/lib/libXrandr.so.2.2.0
a620e000-a620f000 rw-p 00005000 08:04 20298      /usr/lib/libXrandr.so.2.2.0
a6210000-a621c000 r-xp 00000000 08:04 19339      /usr/lib/libXi.so.6.1.0
a621c000-a621d000 rw-p 0000b000 08:04 19339      /usr/lib/libXi.so.6.1.0
a621d000-a621f000 r-xp 00000000 08:04 19347      /usr/lib/libXinerama.so.1.0.0
a621f000-a6220000 rw-p 00001000 08:04 19347      /usr/lib/libXinerama.so.1.0.0
a6220000-a6228000 r-xp 00000000 08:04 21810      /usr/lib/libXcursor.so.1.0.2
a6228000-a6229000 rw-p 00007000 08:04 21810      /usr/lib/libXcursor.so.1.0.2
a6229000-a622d000 r-xp 00000000 08:04 20361      /usr/lib/libXfixes.so.3.1.0
a622d000-a622e000 rw-p 00003000 08:04 20361      /usr/lib/libXfixes.so.3.1.0
a622e000-a6237000 r--p 00000000 08:04 15494      /usr/share/locale/it/LC_MESSAGES/libc.mo
a6237000-a6239000 r--s 00000000 08:04 2765       /var/cache/fontconfig/699564f050ff7e0f9dae359f33bc56a5-le32d4.cache-3
a6239000-a623a000 r--s 00000000 08:04 2735       /var/cache/fontconfig/ec648e9a1aea82bddd4bd6050028158d-le32d4.cache-3
a623a000-a623b000 r--s 00000000 08:04 10499      /var/cache/fontconfig/2bb5794ea0204a417d14a0dee8a6a354-le32d4.cache-3
a623b000-a626f000 r--s 00000000 08:04 11130      /var/cache/fontconfig/f6b893a7224233d96cb72fd88691c0b4-le32d4.cache-3
a626f000-a62b0000 r--s 00000000 08:04 11128      /var/cache/fontconfig/17090aa38d5c6f09fb8c5c354938f1d7-le32d4.cache-3
a62b0000-a62f1000 r--s 00000000 08:04 11127      /var/cache/fontconfig/df311e82a1a24c41a75c2c930223552e-le32d4.cache-3
a62f1000-a64f1000 r--p 00000000 08:04 45118      /usr/lib/locale/locale-archive
a64f1000-a64f4000 rw-p 00000000 00:00 0 
a64f4000-a64f8000 r-xp 00000000 08:04 18012      /usr/lib/libXdmcp.so.6.0.0
a64f8000-a64f9000 rw-p 00003000 08:04 18012      /usr/lib/libXdmcp.so.6.0.0Abortito

Did I do something wrong in the code or in the build process? And what?


The Linux philosophy is 'laugh in the face of danger'. Oops. Wrong one. 'Do it yourself'. That's it. - Linus Torvalds

Offline

#2 2010-12-28 18:26:23

stfn
Member
Registered: 2010-02-28
Posts: 32

Re: Qt simple example crash-on-exit

The problem is that you allocated your QVBoxLayout object on the stack, though it's supposed to be on the heap so that the Qt framework can free the memory on its own once the object is no longer needed.

Offline

#3 2010-12-28 20:45:17

lucak3
Member
From: Italy
Registered: 2010-01-23
Posts: 72

Re: Qt simple example crash-on-exit

You're so right...
I think I need to find a way not to lose myself in that documentation to begin with, I couldn't find notice of this behaviour in Qt docs.


The Linux philosophy is 'laugh in the face of danger'. Oops. Wrong one. 'Do it yourself'. That's it. - Linus Torvalds

Offline

Board footer

Powered by FluxBB