From 0bd01b003f9a6a78fb8af331c44b2e32036b6786 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 30 Nov 2016 12:34:45 +0200 Subject: [PATCH] lib-storage: If mailbox_create() fails, don't leave box in partially opened state. For example with sdbox it may have opened the indexes, but not set mailbox's GUID. A following MAILBOX_METADATA_GUID would then assert-crash because GUID is empty. --- src/lib-storage/mail-storage.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 6963c50c70..fa39e51939 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -1330,6 +1330,13 @@ int mailbox_create(struct mailbox *box, const struct mailbox_update *update, box->creating = FALSE; if (ret == 0) box->list->guid_cache_updated = TRUE; + else if (box->opened) { + /* Creation failed after (partially) opening the mailbox. + It may not be in a valid state, so close it. */ + mail_storage_last_error_push(box->storage); + mailbox_close(box); + mail_storage_last_error_pop(box->storage); + } return ret; } -- 2.47.3