From: Timo Sirainen Date: Mon, 19 Dec 2016 13:31:50 +0000 (+0200) Subject: lib-index: Fix assert-crash if .log creation unexpectedly fails at the end X-Git-Tag: 2.3.0.rc1~2377 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce2312763f6b5fd2da8bfb20847b87f29b063fa8;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Fix assert-crash if .log creation unexpectedly fails at the end Pretty much the only reason for this to happen is if the index directory was deleted while another process still had the index open. Even this doesn't normally trigger this crash, because there are other checks earlier that usually catch it. So it crashes only in some race conditions. Fixes: Error: rename(.../dovecot.index.log.newlock, .../dovecot.index.log) failed: No such file or directory Panic: file mail-transaction-log-file.c: line 105 (mail_transaction_log_file_free): assertion failed: (!file->locked) --- diff --git a/src/lib-index/mail-transaction-log-file.c b/src/lib-index/mail-transaction-log-file.c index 5cc9f60208..410cf59218 100644 --- a/src/lib-index/mail-transaction-log-file.c +++ b/src/lib-index/mail-transaction-log-file.c @@ -786,7 +786,7 @@ mail_transaction_log_file_create2(struct mail_transaction_log_file *file, file->fd = new_fd; ret = mail_transaction_log_file_stat(file, FALSE); - if (need_lock) { + if (need_lock && ret == 0) { /* we'll need to preserve the lock */ if (mail_transaction_log_file_lock(file) < 0) ret = -1; @@ -821,8 +821,12 @@ mail_transaction_log_file_create2(struct mail_transaction_log_file *file, } if (file_dotlock_replace(dotlock, - DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) <= 0) + DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) <= 0) { + /* need to unlock to avoid assert-crash in + mail_transaction_log_file_free() */ + mail_transaction_log_file_unlock(file, "creation failed"); return -1; + } /* success */ file->fd = new_fd;