From: Kevin McCarthy Date: Tue, 23 May 2017 22:53:30 +0000 (-0700) Subject: Fix memory leak when closing mailbox and using the sidebar. X-Git-Tag: neomutt-20170602^2^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=141da62ced3d3be293e680019d63cc388e6ce0e7;p=neomutt Fix memory leak when closing mailbox and using the sidebar. The code updating the sidebar counts decremented the msgcount, but did not set it back to the original value. Which means fastclose was not freeing all the headers. Update the sidebar only when something is deleted, since I don't believe it's required otherwise and the code is a bit cleaner that way. --- diff --git a/mx.c b/mx.c index e8fae7e7d..9a8396f5a 100644 --- a/mx.c +++ b/mx.c @@ -994,6 +994,8 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint) #ifdef USE_SIDEBAR if (purge && ctx->deleted) { + int orig_msgcount = ctx->msgcount; + for (i = 0; i < ctx->msgcount; i++) { if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read) @@ -1002,8 +1004,9 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint) ctx->flagged--; } ctx->msgcount -= ctx->deleted; + mutt_sb_set_buffystats (ctx); + ctx->msgcount = orig_msgcount; } - mutt_sb_set_buffystats (ctx); #endif mx_fastclose_mailbox (ctx);