From: Timo Sirainen Date: Wed, 30 Nov 2016 10:34:45 +0000 (+0200) Subject: lib-storage: If mailbox_create() fails, don't leave box in partially opened state. X-Git-Tag: 2.2.27~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d3426e98463517232a2cf3d571247d25f32333c5;p=thirdparty%2Fdovecot%2Fcore.git 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. --- 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; }