From: Pietro Cerutti Date: Mon, 12 Nov 2018 15:02:45 +0000 (+0000) Subject: Centralize Context cleanup in a dedicated function X-Git-Tag: 2019-10-25~539 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6cb8209307b36325ed85769c4f9b125d60212d30;p=neomutt Centralize Context cleanup in a dedicated function --- diff --git a/mailbox.c b/mailbox.c index 05167bdb1..1a417e7e9 100644 --- a/mailbox.c +++ b/mailbox.c @@ -105,11 +105,15 @@ void mailbox_free(struct Mailbox **m) if (!m || !*m) return; + if (Context && Context->mailbox && Context->mailbox == *m) + { + mx_cleanup_context(Context); + FREE(&Context); + } + FREE(&(*m)->desc); if ((*m)->mdata && (*m)->free_mdata) (*m)->free_mdata(&(*m)->mdata); - if (Context && Context->mailbox && Context->mailbox == *m) - Context = NULL; FREE(m); } diff --git a/mx.c b/mx.c index c26259e59..f580826ca 100644 --- a/mx.c +++ b/mx.c @@ -408,10 +408,7 @@ void mx_fastclose_mailbox(struct Context *ctx) FREE(&ctx->mailbox->hdrs); } FREE(&ctx->mailbox->v2r); - FREE(&ctx->pattern); - if (ctx->limit_pattern) - mutt_pattern_free(&ctx->limit_pattern); - memset(ctx, 0, sizeof(struct Context)); + mx_cleanup_context(ctx); } /** @@ -1687,3 +1684,17 @@ int mx_ac_remove(struct Mailbox *m) account_remove_mailbox(m->account, m); return 0; } + + +/** + * mx_cleanup_context - Release memory and initialize a Context object + * @param ctx Context to cleanup + */ +void mx_cleanup_context(struct Context *ctx) +{ + FREE(&ctx->pattern); + if (ctx->limit_pattern) + mutt_pattern_free(&ctx->limit_pattern); + memset(ctx, 0, sizeof(struct Context)); +} + diff --git a/mx.h b/mx.h index cd4179330..f55ae6a37 100644 --- a/mx.h +++ b/mx.h @@ -284,5 +284,6 @@ const struct MxOps *mx_get_ops(enum MailboxType magic); bool mx_tags_is_supported(struct Context *ctx); void mx_update_context(struct Context *ctx, int new_messages); void mx_update_tables(struct Context *ctx, bool committing); +void mx_cleanup_context(struct Context *ctx); #endif /* MUTT_MX_H */