]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fix assert-crash if .log creation unexpectedly fails at the end
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 19 Dec 2016 13:31:50 +0000 (15:31 +0200)
committerGitLab <gitlab@git.dovecot.net>
Fri, 23 Dec 2016 13:49:35 +0000 (15:49 +0200)
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)

src/lib-index/mail-transaction-log-file.c

index 5cc9f6020855e67275dfe18eab38f0fe772c90b3..410cf59218cf44e706c49a36fc00bf2e00fe4919 100644 (file)
@@ -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;