From: Kevin McCarthy Date: Tue, 23 May 2017 01:18:29 +0000 (-0700) Subject: Don't clean up idata when closing an open-append mailbox. X-Git-Tag: neomutt-20170602^2^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=63d7c5d5e8c56d19c5f87f2934e553c52bd4ea0d;p=neomutt Don't clean up idata when closing an open-append mailbox. open-append borrows the idata just for the connection. The "mailbox specific" part of the idata may be being used by a normal open-mailbox. Don't free the idata "mailbox specific" part when closing an open-append mailbox. Thanks to Will Yardley for discovering the bug as part of testing the revised IMAP fetch_headers code (in the default branch). --- diff --git a/imap/imap.c b/imap/imap.c index f45a516e3..7b1060a99 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1375,6 +1375,14 @@ int imap_close_mailbox (CONTEXT* ctx) if (!idata) return 0; + /* imap_open_mailbox_append() borrows the IMAP_DATA temporarily, + * just for the connection, but does not set idata->ctx to the + * open-append ctx. + * + * So when these are equal, it means we are actually closing the + * mailbox and should clean up idata. Otherwise, we don't want to + * touch idata - it's still being used. + */ if (ctx == idata->ctx) { if (idata->status != IMAP_FATAL && idata->state >= IMAP_SELECTED) @@ -1390,6 +1398,19 @@ int imap_close_mailbox (CONTEXT* ctx) FREE (&(idata->mailbox)); mutt_free_list (&idata->flags); idata->ctx = NULL; + + hash_destroy (&idata->uid_hash, NULL); + + for (i = 0; i < IMAP_CACHE_LEN; i++) + { + if (idata->cache[i].path) + { + unlink (idata->cache[i].path); + FREE (&idata->cache[i].path); + } + } + + mutt_bcache_close (&idata->bcache); } /* free IMAP part of headers */ @@ -1397,18 +1418,6 @@ int imap_close_mailbox (CONTEXT* ctx) /* mailbox may not have fully loaded */ if (ctx->hdrs[i] && ctx->hdrs[i]->data) imap_free_header_data ((IMAP_HEADER_DATA**)&(ctx->hdrs[i]->data)); - hash_destroy (&idata->uid_hash, NULL); - - for (i = 0; i < IMAP_CACHE_LEN; i++) - { - if (idata->cache[i].path) - { - unlink (idata->cache[i].path); - FREE (&idata->cache[i].path); - } - } - - mutt_bcache_close (&idata->bcache); return 0; }