dovecot-2.2: lib-index: If sure mail_index_alloc_cache_destroy_u...

dovecot at dovecot.org dovecot at dovecot.org
Sat Jan 5 01:14:35 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/b53ab1c11843
changeset: 15560:b53ab1c11843
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Dec 18 21:15:19 2012 +0200
description:
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.

diffstat:

 src/lib-index/mail-index-alloc-cache.c |  15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diffs (47 lines):

diff -r 04704d1eb6c3 -r b53ab1c11843 src/lib-index/mail-index-alloc-cache.c
--- 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++;
 	}
 }


More information about the dovecot-cvs mailing list