From ec8c0bdaf1c55dd251af2953644d528b2103dd56 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 25 May 2015 16:07:14 +0200 Subject: Fixed messagequeue. The key someties vanished before we got to removing the value, (it was pure luck that it worked sometimes anyways), and then calling the errorHandler once the resultHandler was already called, lead to a crash in the resource processor. --- common/messagequeue.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'common/messagequeue.cpp') diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp index ccb5362..0704dd3 100644 --- a/common/messagequeue.cpp +++ b/common/messagequeue.cpp @@ -1,6 +1,7 @@ #include "messagequeue.h" #include "storage.h" #include +#include MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) : mStorage(storageRoot, name, Akonadi2::Storage::ReadWrite) @@ -24,16 +25,17 @@ void MessageQueue::dequeue(const std::function bool { - const auto key = QByteArray::fromRawData(static_cast(keyPtr), keySize); + //We need a copy of the key here, otherwise we can't store it in the lambda (the pointers will become invalid) + const auto key = QByteArray(static_cast(keyPtr), keySize); if (Akonadi2::Storage::isInternalKey(key)) { return true; } readValue = true; resultHandler(valuePtr, valueSize, [this, key, errorHandler](bool success) { if (success) { - mStorage.remove(key.data(), key.size(), [errorHandler](const Akonadi2::Storage::Error &error) { - qDebug() << "Error while removing value" << error.message; - errorHandler(Error(error.store, error.code, "Error while removing value: " + error.message)); + mStorage.remove(key.data(), key.size(), [errorHandler, key](const Akonadi2::Storage::Error &error) { + ErrorMsg() << "Error while removing value" << error.message << key; + //Don't call the errorhandler in here, we already called the result handler }); if (isEmpty()) { emit this->drained(); @@ -45,7 +47,7 @@ void MessageQueue::dequeue(const std::function