From: Timo Sirainen Date: Tue, 18 Dec 2012 19:15:19 +0000 (+0200) Subject: lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone... X-Git-Tag: 2.1.13~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bed2aacac5ad4bb86ab034cd9adee8a565a4f1b;p=thirdparty%2Fdovecot%2Fcore.git lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone keeps open. This makes sure that all index files are closed within process when mailbox is deleted. --- diff --git a/src/lib-index/mail-index-alloc-cache.c b/src/lib-index/mail-index-alloc-cache.c index a01dd64b42..7a921f6365 100644 --- a/src/lib-index/mail-index-alloc-cache.c +++ b/src/lib-index/mail-index-alloc-cache.c @@ -22,6 +22,7 @@ struct mail_index_alloc_cache_list { struct mail_index *index; char *mailbox_path; int refcount; + bool referenced; dev_t index_dir_dev; ino_t index_dir_ino; @@ -58,7 +59,7 @@ mail_index_alloc_cache_add(struct mail_index *index, static void mail_index_alloc_cache_list_free(struct mail_index_alloc_cache_list *list) { - if (list->index->open_count > 0) + if (list->referenced) mail_index_close(list->index); mail_index_free(&list->index); i_free(list->mailbox_path); @@ -166,6 +167,15 @@ static void destroy_unrefed(bool all) } else { if (rec->refcount == 0) seen_ref0 = TRUE; + if (all && rec->index->open_count == 1 && + rec->referenced) { + /* we're the only one keeping this index open. + we might be here, because the caller is + deleting this mailbox and wants its indexes + to be closed. so close it. */ + rec->referenced = FALSE; + mail_index_close(rec->index); + } list = &(*list)->next; } } @@ -228,8 +238,9 @@ void mail_index_alloc_cache_index_opened(struct mail_index *index) list->index_dir_dev = st.st_dev; } } - if (list != NULL) { + if (list != NULL && !list->referenced) { /* keep it referenced for ourself */ + list->referenced = TRUE; index->open_count++; } }