]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Panic if at mailbox_free() there are open attribute iterators.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 9 Aug 2017 10:41:34 +0000 (13:41 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Wed, 9 Aug 2017 12:41:54 +0000 (15:41 +0300)
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c
src/lib-storage/mailbox-attribute.c

index bb140577cab2fcb3bb02d52024e58ec261a681c4..0f23fe20f3e5597ba0383735b987848e092fc5fd 100644 (file)
@@ -370,6 +370,7 @@ struct mailbox {
        const char *index_prefix;
        enum mailbox_flags flags;
        unsigned int transaction_count;
+       unsigned int attribute_iter_count;
        enum mailbox_feature enabled_features;
        struct mail_msgpart_partial_cache partial_cache;
        uint32_t vsize_hdr_ext_id;
index f9c0990d786abdde0a6348d1f13595d9fabefd4a..1b16c5c872824686b10d0d566606765ea5652142 100644 (file)
@@ -1381,6 +1381,11 @@ void mailbox_free(struct mailbox **_box)
        mailbox_close(box);
        box->v.free(box);
 
+       if (box->attribute_iter_count != 0) {
+               i_panic("Trying to free mailbox %s with %u open attribute iterators",
+                       box->name, box->attribute_iter_count);
+       }
+
        DLLIST_REMOVE(&box->storage->mailboxes, box);
        mail_storage_obj_unref(box->storage);
        if (box->metadata_pool != NULL)
index 09d76e2940143c84c0ddc3de5dec53e9a9ce0d35..5fce61b9393dcbd39c5a1d9297ddaff7073b3d5e 100644 (file)
@@ -384,6 +384,7 @@ mailbox_attribute_iter_init(struct mailbox *box,
 
        iter = box->v.attribute_iter_init(box, type, prefix);
        i_assert(iter->box != NULL);
+       box->attribute_iter_count++;
 
        /* check which internal attributes may apply */
        t_array_init(&extra_attrs, 4);
@@ -455,13 +456,20 @@ int mailbox_attribute_iter_deinit(struct mailbox_attribute_iter **_iter)
        int ret;
 
        *_iter = NULL;
+
        if (iter->box != NULL) {
                /* not wrapped */
+               i_assert(iter->box->attribute_iter_count > 0);
+               iter->box->attribute_iter_count--;
                return iter->box->v.attribute_iter_deinit(iter);
        }
 
        /* wrapped */
        intiter = (struct mailbox_attribute_internal_iter *)iter;
+
+       i_assert(intiter->real_iter->box->attribute_iter_count > 0);
+       intiter->real_iter->box->attribute_iter_count--;
+
        ret = intiter->real_iter->box->v.attribute_iter_deinit(intiter->real_iter);
        array_free(&intiter->extra_attrs);
        i_free(intiter);