]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
virtual plugin: Fixed assert-crash when closing a virtual mailbox consisting of many...
authorTimo Sirainen <tss@iki.fi>
Thu, 24 Sep 2015 16:07:12 +0000 (19:07 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 24 Sep 2015 16:07:12 +0000 (19:07 +0300)
src/plugins/virtual/virtual-storage.c
src/plugins/virtual/virtual-storage.h

index 792db49d52352290c3d767d29bbe30dc85976149..37d520d48027ae189a8e62050d32f947ccaa1b80 100644 (file)
@@ -325,12 +325,15 @@ virtual_backend_box_close_any_except(struct virtual_mailbox *mbox,
 void virtual_backend_box_opened(struct virtual_mailbox *mbox,
                                struct virtual_backend_box *bbox)
 {
+       i_assert(!bbox->open_tracked);
+
        /* the backend mailbox was already opened. if we didn't get here
           from virtual_backend_box_open() we may need to close a mailbox */
        while (mbox->backends_open_count > mbox->storage->max_open_mailboxes &&
               virtual_backend_box_close_any_except(mbox, bbox))
                ;
 
+       bbox->open_tracked = TRUE;
        mbox->backends_open_count++;
        DLLIST2_APPEND_FULL(&mbox->open_backend_boxes_head,
                            &mbox->open_backend_boxes_tail, bbox,
@@ -367,12 +370,21 @@ void virtual_backend_box_close(struct virtual_mailbox *mbox,
                mail_search_args_deinit(bbox->search_args);
                bbox->search_args_initialized = FALSE;
        }
-       i_assert(mbox->backends_open_count > 0);
-       mbox->backends_open_count--;
-
-       DLLIST2_REMOVE_FULL(&mbox->open_backend_boxes_head,
-                           &mbox->open_backend_boxes_tail, bbox,
-                           prev_open, next_open);
+       if (bbox->open_tracked) {
+               i_assert(mbox->backends_open_count > 0);
+               mbox->backends_open_count--;
+               bbox->open_tracked = FALSE;
+
+               DLLIST2_REMOVE_FULL(&mbox->open_backend_boxes_head,
+                                   &mbox->open_backend_boxes_tail, bbox,
+                                   prev_open, next_open);
+       } else {
+               /* mailbox can be leaked outside our code via
+                  virtual_get_virtual_backend_boxes() and it could have
+                  been opened there. FIXME: maybe we could hook into the
+                  backend open/close functions to do the tracking and
+                  auto-closing. */
+       }
        mailbox_close(bbox->box);
 }
 
index 62bbeb0f666430ed68251d1103ce4f5445e30f45..10d0dd3884d13e033dac6a5f5df570438274e7a1 100644 (file)
@@ -97,6 +97,7 @@ struct virtual_backend_box {
        struct imap_match_glob *glob;
        struct mail_namespace *ns;
 
+       unsigned int open_tracked:1;
        unsigned int open_failed:1;
        unsigned int sync_seen:1;
        unsigned int wildcard:1;