From 141da62ced3d3be293e680019d63cc388e6ce0e7 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Tue, 23 May 2017 15:53:30 -0700 Subject: [PATCH] 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. --- mx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); -- 2.40.0