summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2017-05-15 14:27:12 (GMT)
committerTobias Markmann <tm@ayena.de>2017-05-15 14:34:02 (GMT)
commit33f9a7682a9b40d141900aa7ce302a8e47d4d762 (patch)
tree288ddffe71fb0117bf8d0998c99df54c0d91deb3
parentd93be16eb1bb43ba602fcd7398fc0e46084dbd7f (diff)
downloadswift-33f9a7682a9b40d141900aa7ce302a8e47d4d762.zip
swift-33f9a7682a9b40d141900aa7ce302a8e47d4d762.tar.bz2
Use QPointer to prevent access to potentially freed QtTreeWidget
As the QtTreeWidget and the QtFilterWidget are siblings in their parent widget, it might happen that the QtTreeWidget is deleted before the QtFilterWidget. Using Pointer, we are able to detect this case and can prevent accessing the already deleted QtTreeWidget. QtFilterWidget cannot be made the child of the QtTreeWidget in this case, so this fix uses the QPointers approach as a workaround. SWIFT-247 Test-Information: Tests pass and builds on macOS 10.12.4 with Qt 5.4.2. Change-Id: I3a60006519b580010718c4d2aa94638555c0afdf
-rw-r--r--Swift/QtUI/Roster/QtFilterWidget.cpp12
-rw-r--r--Swift/QtUI/Roster/QtFilterWidget.h5
2 files changed, 15 insertions, 2 deletions
diff --git a/Swift/QtUI/Roster/QtFilterWidget.cpp b/Swift/QtUI/Roster/QtFilterWidget.cpp
index 4df4a39..a52dfff 100644
--- a/Swift/QtUI/Roster/QtFilterWidget.cpp
+++ b/Swift/QtUI/Roster/QtFilterWidget.cpp
@@ -53,6 +53,10 @@ QtFilterWidget::~QtFilterWidget() {
}
bool QtFilterWidget::eventFilter(QObject*, QEvent* event) {
+ if (!treeView_) {
+ return false;
+ }
+
if (event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease ||
// InputMethodQuery got introduced in Qt 5.
@@ -119,6 +123,10 @@ void QtFilterWidget::pushAllFilters() {
}
void QtFilterWidget::updateRosterFilters() {
+ if (!treeView_) {
+ return;
+ }
+
if (fuzzyRosterFilter_) {
if (filterLineEdit_->text().isEmpty()) {
// remove currently installed search filter and put old filters back
@@ -141,6 +149,10 @@ void QtFilterWidget::updateRosterFilters() {
}
void QtFilterWidget::updateSearchFilter() {
+ if (!treeView_) {
+ return;
+ }
+
if (fuzzyRosterFilter_) {
treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
delete fuzzyRosterFilter_;
diff --git a/Swift/QtUI/Roster/QtFilterWidget.h b/Swift/QtUI/Roster/QtFilterWidget.h
index ea3c325..85f607e 100644
--- a/Swift/QtUI/Roster/QtFilterWidget.h
+++ b/Swift/QtUI/Roster/QtFilterWidget.h
@@ -5,7 +5,7 @@
*/
/*
- * Copyright (c) 2016 Isode Limited.
+ * Copyright (c) 2016-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -15,6 +15,7 @@
#include <vector>
#include <QBoxLayout>
+#include <QPointer>
#include <QWidget>
#include <Swift/Controllers/Roster/FuzzyRosterFilter.h>
@@ -46,7 +47,7 @@ class QtFilterWidget : public QWidget {
private:
QtClosableLineEdit* filterLineEdit_;
- QtTreeWidget* treeView_;
+ QPointer<QtTreeWidget> treeView_;
UIEventStream* eventStream_;
std::vector<RosterFilter*> filters_;
QAbstractItemModel* sourceModel_;