pimcommon: autocorrectionwidget - QPointer guard dialogs
ClosedPublic

Authored by winterz on Aug 13 2017, 3:21 PM.

Details

Summary

use QPointer to guard possible crashes with dialog exec

Diff Detail

Repository
R95 PIM: Common Support
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
winterz created this revision.Aug 13 2017, 3:21 PM
Restricted Application added a project: KDE PIM. · View Herald TranscriptAug 13 2017, 3:21 PM
Restricted Application added a subscriber: KDE PIM. · View Herald Transcript
anthonyfieroni added a reviewer: KDE PIM.EditedAug 13 2017, 5:56 PM
anthonyfieroni added a subscriber: anthonyfieroni.

This is not really a problem. When dialog is destroyed (e.g. from DBUS) exec() returns rejected (false) it's not safe when access dlg instance after that.

// Edit:
After quick thinking it can be a problem if destructor can be called twice and it access this pointer.

I'm following the recommendations found in this old blog https://blogs.kde.org/node/3919
Perhaps things have have changed since the KDE4 days??

dkurz added a subscriber: dkurz.Aug 15 2017, 8:54 AM

Objects that live on the stack should not be subject to heap memory management; something that definitively hasn't changed. Memory management in Qt is already quite confusing. This change supports local reasoning about the code. This easily outweighs the micro performance hit.

As one consequence, the destructor of a dialog is called twice if this dialog's parent is deleted before exec returns when QPointer is not used, as anthonyfieroni pointed out in his edit. This is bound to cause trouble.

fwiw: +1 for this diff

dvratil accepted this revision.Aug 15 2017, 2:00 PM
This revision is now accepted and ready to land.Aug 15 2017, 2:00 PM
This revision was automatically updated to reflect the committed changes.

This seems to be the reason that I can no longer build kmail on my openSuse 42.2 (gcc 4.8.5)
Had to make the attached changes.
Can you clarify, please ?

This seems to be the reason that I can no longer build kmail on my openSuse 42.2 (gcc 4.8.5)
Had to make the attached changes.
Can you clarify, please ?

It's not this but similar. Make a separate review.