summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-05-30 00:23:57 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-05-30 00:23:57 +0200
commit18ff58edb3bc186e2114efad34de7ffca803be02 (patch)
tree2e312b1812bda001ca2c68a48cf7cf9711a93e69
parentFix warning (diff)
downloadnheko-18ff58edb3bc186e2114efad34de7ffca803be02.tar.xz
Fix use after free from Qml widget
-rw-r--r--src/ChatPage.cpp8
-rw-r--r--src/timeline/RoomlistModel.cpp3
-rw-r--r--src/timeline/TimelineViewManager.cpp5
3 files changed, 13 insertions, 3 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index 4ad7bd14..0f16f205 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -171,6 +171,14 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
                         activateWindow();
                 });
 
+        connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, [this]() {
+                // ensure the qml context is shutdown before we destroy all other singletons
+                // Otherwise Qml will try to access the room list or settings, after they have been
+                // destroyed
+                topLayout_->removeWidget(view_manager_->getWidget());
+                delete view_manager_->getWidget();
+        });
+
         connect(
           this,
           &ChatPage::initializeViews,
diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index d2ba0dc3..283224f1 100644
--- a/src/timeline/RoomlistModel.cpp
+++ b/src/timeline/RoomlistModel.cpp
@@ -13,7 +13,8 @@
 #include "UserSettingsPage.h"
 
 RoomlistModel::RoomlistModel(TimelineViewManager *parent)
-  : manager(parent)
+  : QAbstractListModel(parent)
+  , manager(parent)
 {
         connect(ChatPage::instance(), &ChatPage::decryptSidebarChanged, this, [this]() {
                 auto decrypt = ChatPage::instance()->userSettings()->decryptSidebar();
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 3b3ea423..dd623f2f 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -129,7 +129,8 @@ TimelineViewManager::userStatus(QString id) const
 }
 
 TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *parent)
-  : imgProvider(new MxcImageProvider())
+  : QObject(parent)
+  , imgProvider(new MxcImageProvider())
   , colorImgProvider(new ColorImageProvider())
   , blurhashProvider(new BlurhashProvider())
   , callManager_(callManager)
@@ -230,7 +231,7 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
                                          "Error: Only enums");
 
 #ifdef USE_QUICK_VIEW
-        view      = new QQuickView();
+        view      = new QQuickView(parent);
         container = QWidget::createWindowContainer(view, parent);
 #else
         view      = new QQuickWidget(parent);