[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdepimlibs/Applications/15.12] akonadi/src/core: Fix possible crash upon application exits (e.g. km
From:       Weng Xuetian <wengxt () gmail ! com>
Date:       2015-12-17 16:21:43
Message-ID: E1a9bJH-0005uw-PL () scm ! kde ! org
[Download RAW message or body]

Git commit c6bf33a9018587e96a350bfd0b2bffde1859db27 by Weng Xuetian.
Committed on 17/12/2015 at 16:19.
Pushed by xuetianweng into branch 'Applications/15.12'.

Fix possible crash upon application exits (e.g. kmail)

Qt lambda connection will not automatically disconnect if no context
qobject is provided. Since SessionPrivate is not a qobject, disconnect
the connection in the destructor to prevent accessing deleted object.

REVIEW: 126395

M  +6    -5    akonadi/src/core/session.cpp
M  +2    -0    akonadi/src/core/session_p.h

http://commits.kde.org/kdepimlibs/c6bf33a9018587e96a350bfd0b2bffde1859db27

diff --git a/akonadi/src/core/session.cpp b/akonadi/src/core/session.cpp
index 4711bf5..5015330 100644
--- a/akonadi/src/core/session.cpp
+++ b/akonadi/src/core/session.cpp
@@ -301,15 +301,16 @@ SessionPrivate::SessionPrivate(Session *parent)
     // Shutdown the thread before QApplication event loop quits - the
     // thread()->wait() mechanism in ConnectionThread dtor crashes sometimes
     // when called from QApplication destructor
-    QObject::connect(qApp, &QCoreApplication::aboutToQuit,
-                     [this]() {
-                        delete connThread;
-                        connThread = Q_NULLPTR;
-                     });
+    connThreadCleanUp = QObject::connect(qApp, &QCoreApplication::aboutToQuit,
+                                         [this]() {
+                                             delete connThread;
+                                             connThread = Q_NULLPTR;
+                                         });
 }
 
 SessionPrivate::~SessionPrivate()
 {
+    QObject::disconnect(connThreadCleanUp);
     delete connThread;
 }
 
diff --git a/akonadi/src/core/session_p.h b/akonadi/src/core/session_p.h
index a61b2f7..1be448e 100644
--- a/akonadi/src/core/session_p.h
+++ b/akonadi/src/core/session_p.h
@@ -29,6 +29,7 @@
 
 #include <QtCore/QQueue>
 #include <QtCore/QThreadStorage>
+#include <QtCore/QMetaObject>
 #include <QFile>
 
 class QIODevice;
@@ -125,6 +126,7 @@ public:
     Session *mParent;
     QThread *thread;
     ConnectionThread *connThread;
+    QMetaObject::Connection connThreadCleanUp;
     QByteArray sessionId;
     bool connected;
     qint64 theNextTag;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic