Review Request 122393: Fix dangling pointer and possible memory leak in knotifications

Xuetian Weng wengxt at gmail.com
Mon Feb 2 20:57:05 UTC 2015


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/122393/
-----------------------------------------------------------

Review request for KDE Frameworks.


Bugs: 342752
    https://bugs.kde.org/show_bug.cgi?id=342752


Repository: knotifications


Description
-------

1. Follow code would crash with current code, because notificationQueue may contain dangling pointer to KNotification.

    #include <QApplication>
    #include <KNotification>
    
    int main(int argc, char* argv[]) {
        QApplication app(argc,argv);

        do {
            KNotification a("NewMessage");
            a.setComponentName("kwrited"); // just a random component for test
            a.sendEvent();
        } while(0);

        app.exec();

        return 0;
    }

This is fixed by remove item from queue in ::close.

2. 342752 might happen because galagoNotifications may contain dangling pointer.
This is fixed by using QPointer in galagoNotifications (instead of in ::close, because it will initiate a dbus call and others may be still willing to wait for finished signal).

If KNotification is already deleted, don't call other related functions on this KNotification.

3. watcher is safer to call deleteLater on watcher first.


Diffs
-----

  src/notifybypopup.cpp 95937fc 

Diff: https://git.reviewboard.kde.org/r/122393/diff/


Testing
-------

Above code doesn't crash anymore.


Thanks,

Xuetian Weng

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20150202/0b379dc8/attachment.html>


More information about the Kde-frameworks-devel mailing list