dovecot-2.0: lib-storage: Panic if deiniting storage before clos...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Apr 7 11:51:59 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/085253f549f8
changeset: 11106:085253f549f8
user: Timo Sirainen <tss at iki.fi>
date: Wed Apr 07 11:51:56 2010 +0300
description:
lib-storage: Panic if deiniting storage before closing its mailboxes.
diffstat:
src/lib-storage/mail-storage-private.h | 8 ++++++++
src/lib-storage/mail-storage.c | 26 +++++++++++++++++++++-----
src/lib-storage/mail-storage.h | 1 -
3 files changed, 29 insertions(+), 6 deletions(-)
diffs (101 lines):
diff -r 5d888efd6d4e -r 085253f549f8 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h Wed Apr 07 11:50:48 2010 +0300
+++ b/src/lib-storage/mail-storage-private.h Wed Apr 07 11:51:56 2010 +0300
@@ -66,7 +66,12 @@
/* private: */
pool_t pool;
struct mail_storage *prev, *next;
+ /* counting number of times mail_storage_create() has returned this
+ same storage. */
int refcount;
+ /* counting number of objects (e.g. mailbox) that have a pointer
+ to this storage. */
+ int obj_refcount;
const char *unique_root_dir;
char *error_string;
@@ -445,6 +450,9 @@
extern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
&mail_index_module_register);
+void mail_storage_obj_ref(struct mail_storage *storage);
+void mail_storage_obj_unref(struct mail_storage *storage);
+
/* Set error message in storage. Critical errors are logged with i_error(),
but user sees only "internal error" message. */
void mail_storage_clear_error(struct mail_storage *storage);
diff -r 5d888efd6d4e -r 085253f549f8 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c Wed Apr 07 11:50:48 2010 +0300
+++ b/src/lib-storage/mail-storage.c Wed Apr 07 11:51:56 2010 +0300
@@ -327,11 +327,6 @@
return 0;
}
-void mail_storage_ref(struct mail_storage *storage)
-{
- storage->refcount++;
-}
-
void mail_storage_unref(struct mail_storage **_storage)
{
struct mail_storage *storage = *_storage;
@@ -345,6 +340,9 @@
return;
}
+ if (storage->obj_refcount != 0)
+ i_panic("Trying to deinit storage before freeing its objects");
+
DLLIST_REMOVE(&storage->user->storages, storage);
if (storage->v.destroy != NULL)
@@ -357,6 +355,21 @@
mail_index_alloc_cache_destroy_unrefed();
}
+void mail_storage_obj_ref(struct mail_storage *storage)
+{
+ i_assert(storage->refcount > 0);
+
+ storage->obj_refcount++;
+}
+
+void mail_storage_obj_unref(struct mail_storage *storage)
+{
+ i_assert(storage->refcount > 0);
+ i_assert(storage->obj_refcount > 0);
+
+ storage->obj_refcount--;
+}
+
void mail_storage_clear_error(struct mail_storage *storage)
{
i_free_and_null(storage->error_string);
@@ -514,6 +527,8 @@
box = storage->v.mailbox_alloc(storage, new_list, name, flags);
hook_mailbox_allocated(box);
} T_END;
+
+ mail_storage_obj_ref(box->storage);
return box;
}
@@ -614,6 +629,7 @@
mailbox_close(box);
box->v.free(box);
+ mail_storage_obj_unref(box->storage);
pool_unref(&box->pool);
}
diff -r 5d888efd6d4e -r 085253f549f8 src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h Wed Apr 07 11:50:48 2010 +0300
+++ b/src/lib-storage/mail-storage.h Wed Apr 07 11:51:56 2010 +0300
@@ -295,7 +295,6 @@
exists. The storage is put into ns->storage. */
int mail_storage_create(struct mail_namespace *ns, const char *driver,
enum mail_storage_flags flags, const char **error_r);
-void mail_storage_ref(struct mail_storage *storage);
void mail_storage_unref(struct mail_storage **storage);
/* Returns the mail storage settings. */
More information about the dovecot-cvs
mailing list