]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: mail_transaction_log_indexid_changed() - Clarify refcount handling
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 10 Aug 2020 17:02:22 +0000 (20:02 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 23 Nov 2020 13:19:54 +0000 (13:19 +0000)
Although the old code worked as well, it wasn't so obvious since the
behavior was slightly different when the log->head had extra references.
Clarify the behavior by always unreferencing after the new log file is
created.

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

index e0b0766b4e7035936329aadc86054bc45c89d0a4..7a0b6810e1e27c00d5ed5ae90a09f09b6bfac0e6 100644 (file)
@@ -202,9 +202,16 @@ void mail_transaction_log_indexid_changed(struct mail_transaction_log *log)
 
        if (log->head != NULL &&
            log->head->hdr.indexid != log->index->indexid) {
-               if (--log->head->refcount == 0)
-                       mail_transaction_log_file_free(&log->head);
+               struct mail_transaction_log_file *old_head = log->head;
+
                (void)mail_transaction_log_create(log, FALSE);
+               if (--old_head->refcount == 0) {
+                       if (old_head == log->head) {
+                               /* failed to create a new log */
+                               log->head = NULL;
+                       }
+                       mail_transaction_log_file_free(&old_head);
+               }
        }
 }