changeset: 6742:7b9763564598
user:      Kevin McCarthy <[email protected]>
date:      Fri Jul 22 14:55:01 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/7b9763564598

Convert buffy_mbox_check() and trash_append() to use local context.

buffy_mbox_check() was leaking the dynamically allocated context.
Rather than add a call to free, just convert it to use a local
variable.

Make the same change to trash_append(), which doesn't need the
dynamically allocated context either.

diffs (75 lines):

diff -r 81ecc31f8197 -r 7b9763564598 buffy.c
--- a/buffy.c   Thu Jul 21 14:00:24 2016 -0700
+++ b/buffy.c   Fri Jul 22 14:55:01 2016 -0700
@@ -417,7 +417,7 @@
 {
   int rc = 0;
   int new_or_changed;
-  CONTEXT *ctx = NULL;
+  CONTEXT ctx;
 
   if (option (OPTCHECKMBOXSIZE))
     new_or_changed = sb->st_size > mailbox->size;
@@ -446,15 +446,15 @@
   if (check_stats &&
       (mailbox->stats_last_checked < sb->st_mtime))
   {
-    if ((ctx = mx_open_mailbox (mailbox->path,
-                                MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | 
MUTT_PEEK,
-                                NULL)) != NULL)
+    if (mx_open_mailbox (mailbox->path,
+                         MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK,
+                         &ctx) != NULL)
     {
-      mailbox->msg_count       = ctx->msgcount;
-      mailbox->msg_unread      = ctx->unread;
-      mailbox->msg_flagged     = ctx->flagged;
-      mailbox->stats_last_checked = ctx->mtime;
-      mx_close_mailbox (ctx, 0);
+      mailbox->msg_count       = ctx.msgcount;
+      mailbox->msg_unread      = ctx.unread;
+      mailbox->msg_flagged     = ctx.flagged;
+      mailbox->stats_last_checked = ctx.mtime;
+      mx_close_mailbox (&ctx, 0);
     }
   }
 
diff -r 81ecc31f8197 -r 7b9763564598 mx.c
--- a/mx.c      Thu Jul 21 14:00:24 2016 -0700
+++ b/mx.c      Fri Jul 22 14:55:01 2016 -0700
@@ -800,7 +800,7 @@
 /* move deleted mails to the trash folder */
 static int trash_append (CONTEXT *ctx)
 {
-  CONTEXT *ctx_trash;
+  CONTEXT ctx_trash;
   int i;
   struct stat st, stc;
   int opt_confappend, rc;
@@ -840,22 +840,20 @@
   }
 #endif
 
-  if ((ctx_trash = mx_open_mailbox (TrashPath, MUTT_APPEND, NULL)) != NULL)
+  if (mx_open_mailbox (TrashPath, MUTT_APPEND, &ctx_trash) != NULL)
   {
     /* continue from initial scan above */
     for (; i < ctx->msgcount ; i++)
       if (ctx->hdrs[i]->deleted  && (!ctx->hdrs[i]->purge))
       {
-        if (mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
+        if (mutt_append_message (&ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
         {
-          mx_close_mailbox (ctx_trash, NULL);
-          FREE (&ctx_trash);
+          mx_close_mailbox (&ctx_trash, NULL);
           return -1;
         }
       }
 
-    mx_close_mailbox (ctx_trash, NULL);
-    FREE (&ctx_trash);
+    mx_close_mailbox (&ctx_trash, NULL);
   }
   else
   {

Reply via email to