kjob::exec and autodeletion
Till Adam
adam at kde.org
Sat Apr 11 20:47:16 BST 2009
Folks,
KJob::exec() uses a secondary event loop to implement synchronous execution of
a job. On OSX (at least), if the job is set to delete itself, that event loop
will get and process the deletion even posted by deleteLater(), just after
emitting result() (which leads to a quit() of the event loop), such that upon
return from exec() the job is already deleted and the subsequent access to the
private object crashes. This does not seem to happen on Linux, at least, but I
seem to remember seeing it happen on Windows as well, somewhere in Kleo, which
does something similar in its job class.
Attached patch works around this issue. I can't make up my mind whether this
is to be considered a bug in Qt, after all the chain of events _should_ be, at
least according to my expectations:
- job emits result
- slot connected to result() syncronously executes, in this case
QEventLooop::quit(), since we are single threaded here, presumably
- job calls deleteLater() on itself
- deletion event gets posted to the event queue
- secondary event loop does no further processing, since it's been quit
- QEventLoop::exec returns to the job's exec(), which started it
- job's exec() finishes processing
- primary event loop processes deletion event and actually deletes the job
Maybe the way that things are hooked into the platform eventing is different,
such that quitting a secondary event loop does not immediately stop all
processing it is doing. Does anyone know?
In any case, shall I commit the workaround, or does someone have a better one?
Till
--
Till Adam <adam at kde.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kjob-exec-autodeletion-fix.diff
Type: text/x-patch
Size: 1076 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090411/c2a63ef7/attachment.bin>
More information about the kde-core-devel
mailing list