/* 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;
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);
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;
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)
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);
box = storage->v.mailbox_alloc(storage, new_list, name, flags);
hook_mailbox_allocated(box);
} T_END;
+
+ mail_storage_obj_ref(box->storage);
return box;
}
mailbox_close(box);
box->v.free(box);
+ mail_storage_obj_unref(box->storage);
pool_unref(&box->pool);
}
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. */