changeset 21251:d29e14e83679

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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 30 Nov 2016 12:34:45 +0200
parents e0aad1bacb5f
children 8868574cd88c
files src/lib-storage/mail-storage.c
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.c	Wed Nov 30 00:28:08 2016 +0200
+++ b/src/lib-storage/mail-storage.c	Wed Nov 30 12:34:45 2016 +0200
@@ -1330,6 +1330,13 @@
 	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;
 }