Mercurial > dovecot > core-2.2
changeset 15560:b53ab1c11843
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.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 18 Dec 2012 21:15:19 +0200 |
parents | 04704d1eb6c3 |
children | 310b3a77a9d1 |
files | src/lib-index/mail-index-alloc-cache.c |
diffstat | 1 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-alloc-cache.c Tue Dec 18 20:48:36 2012 +0200 +++ b/src/lib-index/mail-index-alloc-cache.c Tue Dec 18 21:15:19 2012 +0200 @@ -22,6 +22,7 @@ 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 @@ 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 @@ } 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 @@ 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++; } }