PDA

View Full Version : Can avoid null pointer exception with QObjectCleanupHandler



momeni
27th June 2010, 20:26
Hi All,

I have a piece of code which uses QObjectCleanupHandler in order to be aware about deleted QObjects but it regularly crashes with this backtrace:


#0 0x0000000000000000 in ?? ()
#1 0x00007fb708cc1261 in QObject::disconnect () from /usr/lib/libQtCore.so.4
#2 0x00007fb708d09f80 in QObjectCleanupHandler::qt_metacall () from /usr/lib/libQtCore.so.4
#3 0x00007fb708cbab59 in QObject::event () from /usr/lib/libQtCore.so.4
#4 0x00007fb708caaf1c in QCoreApplication::notifyInternal () from /usr/lib/libQtCore.so.4
#5 0x00007fb708cad697 in QCoreApplicationPrivate::sendPostedEvents () from /usr/lib/libQtCore.so.4
#6 0x00007fb708cd4833 in ?? () from /usr/lib/libQtCore.so.4
#7 0x00007fb7075686c2 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#8 0x00007fb70756c538 in ?? () from /lib/libglib-2.0.so.0
#9 0x00007fb70756c6ec in g_main_context_iteration () from /lib/libglib-2.0.so.0
#10 0x00007fb708cd4373 in QEventDispatcherGlib::processEvents () from /usr/lib/libQtCore.so.4
#11 0x00007fb708ca9842 in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4
#12 0x00007fb708ca9c1c in QEventLoop::exec () from /usr/lib/libQtCore.so.4
#13 0x00007fb708cad95b in QCoreApplication::exec () from /usr/lib/libQtCore.so.4
#14 0x0000000000407b73 in main (argc=1, argv=0x7fffffffd778) at src/main.cpp:63

As it seems, there is a null pointer exception (and so a sigsegv) during the QObjectCleanupHandler activity.
But as I know QObjectCleanupHandler is for detecting deleted QObjects in a safe manner. What may be the root cause of this problem?
Note:

The objects which are monitored with QObjectCleanupHandler are all QThreads.
I can not prepare a small code to reproduce the problem (it is very hard to reproduce it in a small piece of code).


Any idea is appreciated in advance.

momeni
28th June 2010, 06:21
The problem solved :D
For those who may have a similar problem:

The QObjectCleanupHandler needs all monitored objects to be deleted in the same thread!! So monitoring objects from other threads will force the deleted signal to be delivered via an event to the QObjectCleanupHandler object in another thread. So a race condition will be present between when QObjectCleanupHandler access object to disconnect from it and when the object finishes its destructor in its own thread. :)