From a6a126624030cdb616f2b71525e1fca827a41037 Mon Sep 17 00:00:00 2001
From: Peter Kosyh
Date: Sat, 17 Nov 2018 16:24:20 +0300
Subject: [PATCH] mail: IMAP fix deadlock when connection failed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
fLocker must be released in IMAPConnectionWorker::_Worker() before WorkerQuit() call.
Change-Id: I1e622a711fa3349986560af1118b158696025844
Reviewed-on: https://review.haiku-os.org/705
Reviewed-by: Axel Dörfler
---
.../imap/IMAPConnectionWorker.cpp | 21 ++++++++-----------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPConnectionWorker.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPConnectionWorker.cpp
index f30625e977..ef870c4528 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPConnectionWorker.cpp
+++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPConnectionWorker.cpp
@@ -717,6 +717,8 @@ IMAPConnectionWorker::MessageExpungeReceived(uint32 index)
status_t
IMAPConnectionWorker::_Worker()
{
+ status_t status = B_OK;
+
while (!fStopped) {
BAutolock locker(fLocker);
@@ -736,21 +738,16 @@ IMAPConnectionWorker::_Worker()
CommandDeleter deleter(*this, command);
- status_t status = B_OK;
-
- if (dynamic_cast(command) == NULL) // do not connect on QuitCommand
+ if (dynamic_cast(command) == NULL) { // do not connect on QuitCommand
status = _Connect();
-
- if (status != B_OK) {
- fOwner.WorkerQuit(this);
- return status;
+ if (status != B_OK)
+ break;
}
status = command->Process(*this);
- if (status != B_OK) {
- fOwner.WorkerQuit(this);
- return status;
- }
+ if (status != B_OK)
+ break;
+
if (!command->IsDone()) {
deleter.Detach();
command->SetContinuation();
@@ -759,7 +756,7 @@ IMAPConnectionWorker::_Worker()
}
fOwner.WorkerQuit(this);
- return B_OK;
+ return status;
}