diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-25 16:07:14 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-25 16:07:14 +0200 |
commit | ec8c0bdaf1c55dd251af2953644d528b2103dd56 (patch) | |
tree | 4a41372e4e9f6212a7ca3d5dd7182304295c12d3 /common/messagequeue.cpp | |
parent | 5d349ac5823d1f9c3aed04c27e363e5d703e93ec (diff) | |
download | sink-ec8c0bdaf1c55dd251af2953644d528b2103dd56.tar.gz sink-ec8c0bdaf1c55dd251af2953644d528b2103dd56.zip |
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.
Diffstat (limited to 'common/messagequeue.cpp')
-rw-r--r-- | common/messagequeue.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
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 @@ | |||
1 | #include "messagequeue.h" | 1 | #include "messagequeue.h" |
2 | #include "storage.h" | 2 | #include "storage.h" |
3 | #include <QDebug> | 3 | #include <QDebug> |
4 | #include <log.h> | ||
4 | 5 | ||
5 | MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) | 6 | MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) |
6 | : mStorage(storageRoot, name, Akonadi2::Storage::ReadWrite) | 7 | : mStorage(storageRoot, name, Akonadi2::Storage::ReadWrite) |
@@ -24,16 +25,17 @@ void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::fu | |||
24 | { | 25 | { |
25 | bool readValue = false; | 26 | bool readValue = false; |
26 | mStorage.scan("", [this, resultHandler, errorHandler, &readValue](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { | 27 | mStorage.scan("", [this, resultHandler, errorHandler, &readValue](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { |
27 | const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize); | 28 | //We need a copy of the key here, otherwise we can't store it in the lambda (the pointers will become invalid) |
29 | const auto key = QByteArray(static_cast<char*>(keyPtr), keySize); | ||
28 | if (Akonadi2::Storage::isInternalKey(key)) { | 30 | if (Akonadi2::Storage::isInternalKey(key)) { |
29 | return true; | 31 | return true; |
30 | } | 32 | } |
31 | readValue = true; | 33 | readValue = true; |
32 | resultHandler(valuePtr, valueSize, [this, key, errorHandler](bool success) { | 34 | resultHandler(valuePtr, valueSize, [this, key, errorHandler](bool success) { |
33 | if (success) { | 35 | if (success) { |
34 | mStorage.remove(key.data(), key.size(), [errorHandler](const Akonadi2::Storage::Error &error) { | 36 | mStorage.remove(key.data(), key.size(), [errorHandler, key](const Akonadi2::Storage::Error &error) { |
35 | qDebug() << "Error while removing value" << error.message; | 37 | ErrorMsg() << "Error while removing value" << error.message << key; |
36 | errorHandler(Error(error.store, error.code, "Error while removing value: " + error.message)); | 38 | //Don't call the errorhandler in here, we already called the result handler |
37 | }); | 39 | }); |
38 | if (isEmpty()) { | 40 | if (isEmpty()) { |
39 | emit this->drained(); | 41 | emit this->drained(); |
@@ -45,7 +47,7 @@ void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::fu | |||
45 | return false; | 47 | return false; |
46 | }, | 48 | }, |
47 | [errorHandler](const Akonadi2::Storage::Error &error) { | 49 | [errorHandler](const Akonadi2::Storage::Error &error) { |
48 | qDebug() << "Error while retrieving value" << error.message; | 50 | ErrorMsg() << "Error while retrieving value" << error.message; |
49 | errorHandler(Error(error.store, error.code, error.message)); | 51 | errorHandler(Error(error.store, error.code, error.message)); |
50 | } | 52 | } |
51 | ); | 53 | ); |