changeset 13580:b7995a25c052

lib-storage: Keep mail_user referenced while storage objects exist. This allows unreferencing mail_user after mailbox_alloc() and having it freed on mailbox_free().
author Timo Sirainen <tss@iki.fi>
date Sun, 02 Oct 2011 16:34:41 +0300
parents f41a3dd03be2
children ac9fecc9202e
files src/lib-storage/mail-storage.c
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.c	Sun Oct 02 16:33:51 2011 +0300
+++ b/src/lib-storage/mail-storage.c	Sun Oct 02 16:34:41 2011 +0300
@@ -419,7 +419,8 @@
 {
 	i_assert(storage->refcount > 0);
 
-	storage->obj_refcount++;
+	if (storage->obj_refcount++ == 0)
+		mail_user_ref(storage->user);
 }
 
 void mail_storage_obj_unref(struct mail_storage *storage)
@@ -427,7 +428,10 @@
 	i_assert(storage->refcount > 0);
 	i_assert(storage->obj_refcount > 0);
 
-	storage->obj_refcount--;
+	if (--storage->obj_refcount == 0) {
+		struct mail_user *user = storage->user;
+		mail_user_unref(&user);
+	}
 }
 
 void mail_storage_clear_error(struct mail_storage *storage)