]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: If mailbox_create() fails, don't leave box in partially opened state.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 30 Nov 2016 10:34:45 +0000 (12:34 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 3 Dec 2016 16:45:02 +0000 (18:45 +0200)
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

index 6963c50c70006d49700a7c63d1b41effcd4ab68b..fa39e51939d95c8eba1f0cbd0f36a8869202cd37 100644 (file)
@@ -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;
 }