Skip to content

Fix crash due to deleteLater() + nested event loop

Fabian Vogt requested to merge work/fvogt/kde486283 into master

KMEditItemCommand::execute creates a connection that does deleteLater(), but also calls KMComposerWin::setMessage which creates a nested QEventLoop in Kleo::KeyCache::Private::ensureCachePopulated. This nested event loop thus deletes KMEditItemCommand within KMEditItemCommand::execute, causing a crash.

Fix this by creating the connection for deleteLater as late as possible and also call setDeletesItself(true) for good measure.

BUG: 486283

CC @knauss: The nested event loop is caused by your commit cccd9654:

#16 0x00007fffe97993db in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt6Core.so.6
#17 0x00007fffe865ca15 in Kleo::KeyCache::Private::ensureCachePopulated() const () at /lib64/libKPim6Libkleo.so.6
#18 0x00007fffe864f5b5 in Kleo::KeyCache::findByKeyIDOrFingerprint(char const*) const () at /lib64/libKPim6Libkleo.so.6
#19 0x00007ffff7be905a in KMComposerWin::updateComposerAfterIdentityChanged (this=0x2e46100, ident=..., uoid=845825249, wasModified=true) at /home/fabian/kderepos/kmail/src/editor/kmcomposerwin.cpp:3460
#20 0x00007ffff7be7dc3 in KMComposerWin::slotIdentityChanged (this=0x2e46100, uoid=845825249, initialChange=true) at /home/fabian/kderepos/kmail/src/editor/kmcomposerwin.cpp:3382
#21 0x00007ffff7bdc1fc in KMComposerWin::setMessage (this=0x2e46100, newMsg=..., lastSignState=false, lastEncryptState=false, mayAutoSign=false, allowDecryption=true, isModified=false)
    at /home/fabian/kderepos/kmail/src/editor/kmcomposerwin.cpp:1859

Maybe that can be done async instead, which would avoid the event loop and make it faster as well?

Merge request reports

Loading