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,
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);
}