]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix crash during shutdown
authorDavid Hallas <david@davidhallas.dk>
Sat, 16 Feb 2019 15:50:42 +0000 (16:50 +0100)
committerDavid Hallas <david@davidhallas.dk>
Mon, 18 Feb 2019 07:58:11 +0000 (08:58 +0100)
Summary:
Fix crash during shutdown. The root cause is that when Dolphin in stopped as
part of an activity, the KItemListViewAccessible destructor is called after
QApplication::exec has returned causing Qt to already having cleaned up the
QAccessibleInterface instances kept in KItemListViewAccessible. Instead of
storing the pointers to QAccessibleInterface we store the QAccessible::Id so
that we can use the QAccessible::deleteAccessibleInterface function for
deleting the instances.

BUG: 402784

Test Plan:
I wasn't able to reproduce the crash in the first place, but I have just
opened and closed Dolphin a few times and verified the the QAccessibleInterface
instances are correctly cleaned up.

Reviewers: #dolphin, elvisangelaccio, ngraham

Reviewed By: #dolphin, elvisangelaccio

Subscribers: kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D19083

src/kitemviews/kitemlistviewaccessible.cpp
src/kitemviews/kitemlistviewaccessible.h

index 4d1b28b9fd35337f8e6729333f93a2258d592877..8fe8a6ef893de1d5b37af1b66385a90f9e23d9ad 100644 (file)
@@ -44,10 +44,9 @@ KItemListViewAccessible::KItemListViewAccessible(KItemListView* view_) :
 
 KItemListViewAccessible::~KItemListViewAccessible()
 {
-    foreach (QAccessibleInterface* child, m_cells) {
-        if (child) {
-            QAccessible::Id childId = QAccessible::uniqueId(child);
-            QAccessible::deleteAccessibleInterface(childId);
+    foreach (AccessibleIdWrapper idWrapper, m_cells) {
+        if (idWrapper.isValid) {
+            QAccessible::deleteAccessibleInterface(idWrapper.id);
         }
     }
 }
@@ -75,13 +74,13 @@ QAccessibleInterface* KItemListViewAccessible::cell(int index) const
     }
     Q_ASSERT(index < m_cells.size());
 
-    QAccessibleInterface* child = m_cells.at(index);
-    if (!child) {
-        child = new KItemListAccessibleCell(view(), index);
-        m_cells.insert(index, child);
-        QAccessible::registerAccessibleInterface(child);
+    AccessibleIdWrapper idWrapper = m_cells.at(index);
+    if (!idWrapper.isValid) {
+        idWrapper.id = QAccessible::registerAccessibleInterface(new KItemListAccessibleCell(view(), index));
+        idWrapper.isValid = true;
+        m_cells.insert(index, idWrapper);
     }
-    return child;
+    return QAccessible::accessibleInterface(idWrapper.id);
 }
 
 QAccessibleInterface* KItemListViewAccessible::cellAt(int row, int column) const
@@ -266,6 +265,12 @@ QAccessibleInterface* KItemListViewAccessible::child(int index) const
     return nullptr;
 }
 
+KItemListViewAccessible::AccessibleIdWrapper::AccessibleIdWrapper() :
+    isValid(false),
+    id(0)
+{
+}
+
 // Table Cell
 
 KItemListAccessibleCell::KItemListAccessibleCell(KItemListView* view, int index) :
index fdc3ff1a3a73adaeae3854019bd3001e32c5b816..3e39e239920603b78f930752fa72775313169229 100644 (file)
@@ -86,7 +86,13 @@ protected:
     inline QAccessibleInterface* cell(int index) const;
 
 private:
-    mutable QVector<QAccessibleInterface*> m_cells;
+    class AccessibleIdWrapper {
+    public:
+        AccessibleIdWrapper();
+        bool isValid;
+        QAccessible::Id id;
+    };
+    mutable QVector<AccessibleIdWrapper> m_cells;
 };
 
 class DOLPHIN_EXPORT KItemListAccessibleCell: public QAccessibleInterface, public QAccessibleTableCellInterface