]> granicus.if.org Git - neomutt/commitdiff
Centralize Context cleanup in a dedicated function
authorPietro Cerutti <gahr@gahr.ch>
Mon, 12 Nov 2018 15:02:45 +0000 (15:02 +0000)
committerPietro Cerutti <gahr@gahr.ch>
Mon, 12 Nov 2018 15:02:45 +0000 (15:02 +0000)
mailbox.c
mx.c
mx.h

index 05167bdb1105375759f80880964b7924e6159e00..1a417e7e9257091ba06ee28441b301d20609f969 100644 (file)
--- 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 c26259e596f4826448bd1e6b0e37270fee947f70..f580826ca5c8755532e36a71ab67c418e771f1f6 100644 (file)
--- 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 cd4179330feb5de98b7a71870c05818e2fdf64dc..f55ae6a376322a62b83b207d841cb615394a3ad4 100644 (file)
--- 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 */