]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Keep mail_user referenced while storage objects exist.
authorTimo Sirainen <tss@iki.fi>
Sun, 2 Oct 2011 13:34:41 +0000 (16:34 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 2 Oct 2011 13:34:41 +0000 (16:34 +0300)
This allows unreferencing mail_user after mailbox_alloc() and having it
freed on mailbox_free().

src/lib-storage/mail-storage.c

index 69141c116ce0646d89aa3b2f88725b7760221e00..da55f1ee8d4f83738d43b6a8c3fed2bdde065660 100644 (file)
@@ -419,7 +419,8 @@ void mail_storage_obj_ref(struct mail_storage *storage)
 {
        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 @@ void mail_storage_obj_unref(struct mail_storage *storage)
        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)