]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Give better assert-crashes if view or log view isn't closed.
authorTimo Sirainen <tss@iki.fi>
Thu, 24 Feb 2011 11:19:05 +0000 (13:19 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 24 Feb 2011 11:19:05 +0000 (13:19 +0200)
Earlier it should have also assert-crashed with "log->files == NULL", which
didn't make it clear enough why the files aren't NULL.

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

index 2b97966dc02f7f2d0d30a743b7e1f885523aad16..ad7d5209ebc899e56afeb6483e16177e113d10f2 100644 (file)
@@ -221,6 +221,8 @@ struct mail_index {
        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 *);
 
index 67493f6f616fb86337e206ffc8f89a294c973400..3cee97228ba5469b3d20859e635ae10a37fefabb 100644 (file)
@@ -31,6 +31,8 @@ void mail_index_view_clone(struct mail_index_view *dest,
 
        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 @@ void mail_index_view_ref(struct mail_index_view *view)
 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 @@ mail_index_view_open_with_map(struct mail_index *index,
 
        i_array_init(&view->module_contexts,
                     I_MIN(5, mail_index_module_register.id));
+
+       index->view_count++;
        return view;
 }
 
index 7b2374abdfc4e8b88a6f261dc6a4558928501f08..ad650f192967f123440c115819642f8d1e273308 100644 (file)
@@ -585,6 +585,9 @@ void mail_index_close(struct mail_index *index)
        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);
 
index c9bbb711cec1a5be175dc13d4e707761105299c1..ab28623952d3714fb59c0f7e753d6ae6de70fa5c 100644 (file)
@@ -58,14 +58,6 @@ void mail_transaction_log_view_close(struct mail_transaction_log_view **_view)
        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,
index c6ed70fae29ebe19f019d6dc2bd95850949061ed..d4af0114cdac0cda8620467a53d31d0392bb54ca 100644 (file)
@@ -125,7 +125,7 @@ int mail_transaction_log_create(struct mail_transaction_log *log, bool reset)
 
 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);
index 08a6f686da368fdbd2184eedf180359e6472e628..cb7fe03593d1abc9ba419c26e6fa73880e648707 100644 (file)
@@ -253,8 +253,6 @@ mail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view,
 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,