From: Timo Sirainen Date: Mon, 10 Aug 2020 17:02:22 +0000 (+0300) Subject: lib-index: mail_transaction_log_indexid_changed() - Clarify refcount handling X-Git-Tag: 2.3.14.rc1~318 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=268de25bd48f1d102e2fd3b6813793489c449167;p=thirdparty%2Fdovecot%2Fcore.git lib-index: mail_transaction_log_indexid_changed() - Clarify refcount handling 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. --- diff --git a/src/lib-index/mail-transaction-log.c b/src/lib-index/mail-transaction-log.c index e0b0766b4e..7a0b6810e1 100644 --- a/src/lib-index/mail-transaction-log.c +++ b/src/lib-index/mail-transaction-log.c @@ -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); + } } }