]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fix potential assert-crash when rotating log file
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 20 Sep 2019 12:48:10 +0000 (15:48 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 31 Jan 2020 12:36:10 +0000 (12:36 +0000)
Unlock the old head file before attempting to clean it. Fixes:

Panic: file mail-transaction-log.c: line 229 (mail_transaction_logs_clean): assertion failed: (!file->locked || file->refcount > 0)

This seems to only have happened during new obox index merging.

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

index 044153f9cddb5db9cb46db40b971b6dc048b0393..5a9cee1623be5a9a22e72cb7b4a5e95153bb6e45 100644 (file)
@@ -260,7 +260,7 @@ bool mail_transaction_log_want_rotate(struct mail_transaction_log *log)
 
 int mail_transaction_log_rotate(struct mail_transaction_log *log, bool reset)
 {
-       struct mail_transaction_log_file *file;
+       struct mail_transaction_log_file *file, *old_head;
        const char *path = log->head->filepath;
        struct stat st;
        int ret;
@@ -304,15 +304,15 @@ int mail_transaction_log_rotate(struct mail_transaction_log *log, bool reset)
                i_assert(file->locked);
        }
 
-       if (--log->head->refcount == 0)
-               mail_transaction_logs_clean(log);
-       else {
-               /* the newly created log file is already locked */
-               mail_transaction_log_file_unlock(log->head,
-                       !log->index->log_sync_locked ? "rotating" :
-                       "rotating while syncing");
-       }
+       old_head = log->head;
        mail_transaction_log_set_head(log, file);
+
+       /* the newly created log file is already locked */
+       mail_transaction_log_file_unlock(old_head,
+               !log->index->log_sync_locked ? "rotating" :
+               "rotating while syncing");
+       if (--old_head->refcount == 0)
+               mail_transaction_logs_clean(log);
        return 0;
 }