changeset 12762:74300385cce0

lib-index: Give better assert-crashes if view or log view isn't closed. Earlier it should have also assert-crashed with "log->files == NULL", which didn't make it clear enough why the files aren't NULL.
author Timo Sirainen <tss@iki.fi>
date Thu, 24 Feb 2011 13:19:05 +0200
parents 3e8ee35da672
children 345100da8c67
files src/lib-index/mail-index-private.h src/lib-index/mail-index-view.c src/lib-index/mail-index.c src/lib-index/mail-transaction-log-view.c src/lib-index/mail-transaction-log.c src/lib-index/mail-transaction-log.h
diffstat 6 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-private.h	Thu Feb 24 12:57:31 2011 +0200
+++ b/src/lib-index/mail-index-private.h	Thu Feb 24 13:19:05 2011 +0200
@@ -221,6 +221,8 @@
 	uint32_t keywords_ext_id;
 	uint32_t modseq_ext_id;
 
+	unsigned int view_count;
+
 	/* Module-specific contexts. */
 	ARRAY_DEFINE(module_contexts, union mail_index_module_context *);
 
--- a/src/lib-index/mail-index-view.c	Thu Feb 24 12:57:31 2011 +0200
+++ b/src/lib-index/mail-index-view.c	Thu Feb 24 13:19:05 2011 +0200
@@ -31,6 +31,8 @@
 
 	i_array_init(&dest->module_contexts,
 		     I_MIN(5, mail_index_module_register.id));
+
+	dest->index->view_count++;
 }
 
 void mail_index_view_ref(struct mail_index_view *view)
@@ -41,6 +43,9 @@
 static void view_close(struct mail_index_view *view)
 {
 	i_assert(view->refcount == 0);
+	i_assert(view->index->view_count > 0);
+
+	view->index->view_count--;
 
 	mail_transaction_log_view_close(&view->log_view);
 
@@ -614,6 +619,8 @@
 
 	i_array_init(&view->module_contexts,
 		     I_MIN(5, mail_index_module_register.id));
+
+	index->view_count++;
 	return view;
 }
 
--- a/src/lib-index/mail-index.c	Thu Feb 24 12:57:31 2011 +0200
+++ b/src/lib-index/mail-index.c	Thu Feb 24 13:19:05 2011 +0200
@@ -585,6 +585,9 @@
 	if (--index->open_count > 0)
 		return;
 
+	i_assert(!index->syncing);
+	i_assert(index->view_count == 0);
+
 	if (index->map != NULL)
 		mail_index_unmap(&index->map);
 
--- a/src/lib-index/mail-transaction-log-view.c	Thu Feb 24 12:57:31 2011 +0200
+++ b/src/lib-index/mail-transaction-log-view.c	Thu Feb 24 13:19:05 2011 +0200
@@ -58,14 +58,6 @@
 	i_free(view);
 }
 
-void mail_transaction_log_views_close(struct mail_transaction_log *log)
-{
-	struct mail_transaction_log_view *view;
-
-	for (view = log->views; view != NULL; view = view->next)
-		view->log = NULL;
-}
-
 int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
 				  uint32_t min_file_seq, uoff_t min_file_offset,
 				  uint32_t max_file_seq, uoff_t max_file_offset,
--- a/src/lib-index/mail-transaction-log.c	Thu Feb 24 12:57:31 2011 +0200
+++ b/src/lib-index/mail-transaction-log.c	Thu Feb 24 13:19:05 2011 +0200
@@ -125,7 +125,7 @@
 
 void mail_transaction_log_close(struct mail_transaction_log *log)
 {
-	mail_transaction_log_views_close(log);
+	i_assert(log->views == NULL);
 
 	if (log->open_file != NULL)
 		mail_transaction_log_file_free(&log->open_file);
--- a/src/lib-index/mail-transaction-log.h	Thu Feb 24 12:57:31 2011 +0200
+++ b/src/lib-index/mail-transaction-log.h	Thu Feb 24 13:19:05 2011 +0200
@@ -253,8 +253,6 @@
 bool
 mail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view);
 
-void mail_transaction_log_views_close(struct mail_transaction_log *log);
-
 int mail_transaction_log_append_begin(struct mail_index *index, bool external,
 				      struct mail_transaction_log_append_ctx **ctx_r);
 void mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx,