summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-09-19 08:41:33 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-09-19 08:41:33 (GMT)
commit6f1a9e76a329eeaa5000108b839feefd84108133 (patch)
tree6f03711c9739435a9d1db839d332575272cde49a
parentc6db044c3788477eac0fd27d3b3e7676f9785acb (diff)
Some more crash fixes in handling of NotificationSubscribers
-rw-r--r--src/server/notificationmanager.cpp21
-rw-r--r--src/server/notificationmanager.h1
-rw-r--r--src/server/notificationsubscriber.cpp3
3 files changed, 12 insertions, 13 deletions
diff --git a/src/server/notificationmanager.cpp b/src/server/notificationmanager.cpp
index e3e9c39..920af53 100644
--- a/src/server/notificationmanager.cpp
+++ b/src/server/notificationmanager.cpp
@@ -85,19 +85,6 @@ void NotificationManager::registerConnection(quintptr socketDescriptor)
NotificationSubscriber *subscriber = new NotificationSubscriber(this, socketDescriptor);
qCDebug(AKONADISERVER_LOG) << "New notification connection (registered as" << subscriber << ")";
- connect(subscriber, &QObject::destroyed,
- this, [this, subscriber]() {
- // Can't use mSubscribers.remove() because that would try to create
- // a QPointer for the subscriber pointer triggering a Q_ASSERT in Qt
- // (see QtSharedPointer::ExternalRefCountData::getAndRef)
- auto it = std::find_if(mSubscribers.begin(), mSubscribers.end(),
- [subscriber](const QPointer<NotificationSubscriber> &qptr) {
- return qptr.data() == subscriber;
- });
- if (it != mSubscribers.end()) {
- mSubscribers.erase(it);
- }
- });
connect(subscriber, &NotificationSubscriber::notificationDebuggingChanged,
this, [this](bool enabled) {
if (enabled) {
@@ -112,6 +99,12 @@ void NotificationManager::registerConnection(quintptr socketDescriptor)
mSubscribers.push_back(subscriber);
}
+void NotificationManager::forgetSubscriber(NotificationSubscriber *subscriber)
+{
+ Q_ASSERT(QThread::currentThread() == thread());
+ mSubscribers.removeOne(subscriber);
+}
+
void NotificationManager::connectNotificationCollector(NotificationCollector *collector)
{
connect(collector, &NotificationCollector::notify,
@@ -167,6 +160,8 @@ private:
void NotificationManager::emitPendingNotifications()
{
+ Q_ASSERT(QThread::currentThread() == thread());
+
if (mNotifications.isEmpty()) {
return;
}
diff --git a/src/server/notificationmanager.h b/src/server/notificationmanager.h
index 8eb5b45..0a409bf 100644
--- a/src/server/notificationmanager.h
+++ b/src/server/notificationmanager.h
@@ -46,6 +46,7 @@ public:
virtual ~NotificationManager();
void connectNotificationCollector(NotificationCollector *collector);
+ void forgetSubscriber(NotificationSubscriber *subscriber);
public Q_SLOTS:
void registerConnection(quintptr socketDescriptor);
diff --git a/src/server/notificationsubscriber.cpp b/src/server/notificationsubscriber.cpp
index 887880b..ca33c96 100644
--- a/src/server/notificationsubscriber.cpp
+++ b/src/server/notificationsubscriber.cpp
@@ -147,6 +147,7 @@ void NotificationSubscriber::disconnectSubscriber()
disconnect(mSocket, &QLocalSocket::disconnected,
this, &NotificationSubscriber::socketDisconnected);
mSocket->close();
+ mManager->forgetSubscriber(this);
deleteLater();
}
@@ -670,6 +671,8 @@ void NotificationSubscriber::writeNotification(const Protocol::ChangeNotificatio
void NotificationSubscriber::writeCommand(qint64 tag, const Protocol::Command& cmd)
{
+ Q_ASSERT(QThread::currentThread() == thread());
+
QDataStream stream(mSocket);
stream << tag;
Protocol::serialize(mSocket, cmd);