]> granicus.if.org Git - neomutt/commitdiff
free on mx_mbox_close
authorRichard Russon <rich@flatcap.org>
Mon, 27 Aug 2018 20:35:07 +0000 (21:35 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 27 Aug 2018 22:18:58 +0000 (23:18 +0100)
commands.c
compose.c
curs_main.c
editmsg.c
mailbox.c
mutt_attach.c
mx.c
mx.h
pop/pop.c
postpone.c
sendlib.c

index 2f3775390caec7c954e987083088de3cdd46bf79..6331bb3a2b682a70a780e263890e89507572e45d 100644 (file)
@@ -1003,8 +1003,7 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt)
     {
       if (mutt_save_message_ctx(h, delete, decode, decrypt, savectx) != 0)
       {
-        mx_mbox_close(savectx, NULL);
-        FREE(&savectx);
+        mx_mbox_close(&savectx, NULL);
         return -1;
       }
 #ifdef USE_COMPRESSED
@@ -1053,16 +1052,14 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt)
 #endif
       if (rc != 0)
       {
-        mx_mbox_close(savectx, NULL);
-        FREE(&savectx);
+        mx_mbox_close(&savectx, NULL);
         return -1;
       }
     }
 
     const bool need_mailbox_cleanup = ((savectx->magic == MUTT_MBOX) || (savectx->magic == MUTT_MMDF));
 
-    mx_mbox_close(savectx, NULL);
-    FREE(&savectx);
+    mx_mbox_close(&savectx, NULL);
 
     if (need_mailbox_cleanup)
       mutt_mailbox_cleanup(buf, &st);
index 6690cb2655415673a4f0d6d503503093d9d9b3ea..5322b7ed8ea232a947a7bed1bdd38f01d340c9fe 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -1460,8 +1460,7 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen,
 
         if (!ctx->msgcount)
         {
-          mx_mbox_close(ctx, NULL);
-          FREE(&ctx);
+          mx_mbox_close(&ctx, NULL);
           mutt_error(_("No messages in that folder"));
           break;
         }
@@ -1505,10 +1504,12 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen,
         menu->redraw |= REDRAW_FULL;
 
         if (close == OP_QUIT)
-          mx_mbox_close(Context, NULL);
+          mx_mbox_close(&Context, NULL);
         else
+        {
           mx_fastclose_mailbox(Context);
-        FREE(&Context);
+          FREE(&Context);
+        }
 
         /* go back to the folder we started from */
         Context = this;
index bcf47e6b8c2abfdade119afa420381c6ddced7ae..f4d3bed3287dae2f05cbb158cebd37e96cfd8591 100644 (file)
@@ -521,7 +521,7 @@ static int main_change_folder(struct Menu *menu, int op, char *buf,
       new_last_folder = mutt_str_strdup(Context->path);
     *oldcount = Context ? Context->msgcount : 0;
 
-    int check = mx_mbox_close(Context, index_hint);
+    int check = mx_mbox_close(&Context, index_hint);
     if (check != 0)
     {
       if (check == MUTT_NEW_MAIL || check == MUTT_REOPENED)
@@ -532,7 +532,6 @@ static int main_change_folder(struct Menu *menu, int op, char *buf,
       menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
       return 0;
     }
-    FREE(&Context);
     FREE(&LastFolder);
     LastFolder = new_last_folder;
   }
@@ -1591,7 +1590,7 @@ int mutt_index_menu(void)
 
           mutt_startup_shutdown_hook(MUTT_SHUTDOWN_HOOK);
 
-          if (!Context || (check = mx_mbox_close(Context, &index_hint)) == 0)
+          if (!Context || (check = mx_mbox_close(&Context, &index_hint)) == 0)
             done = true;
           else
           {
@@ -1731,13 +1730,12 @@ int mutt_index_menu(void)
       case OP_MAIN_IMAP_LOGOUT_ALL:
         if (Context && Context->magic == MUTT_IMAP)
         {
-          if (mx_mbox_close(Context, &index_hint) != 0)
+          if (mx_mbox_close(&Context, &index_hint) != 0)
           {
             OptSearchInvalid = true;
             menu->redraw = REDRAW_FULL;
             break;
           }
-          FREE(&Context);
         }
         imap_logout_all();
         mutt_message(_("Logged out of IMAP servers"));
index 8410c8d49da3e0727d649bd369db778d95597111..353a3f3a9dbfd286da8672f63bfa7402690f26c5 100644 (file)
--- a/editmsg.c
+++ b/editmsg.c
@@ -97,8 +97,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade
   rc = mutt_append_message(tmpctx, ctx, cur, 0, chflags);
   oerrno = errno;
 
-  mx_mbox_close(tmpctx, NULL);
-  FREE(&tmpctx);
+  mx_mbox_close(&tmpctx, NULL);
 
   if (rc == -1)
   {
@@ -219,8 +218,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade
   if (!msg)
   {
     mutt_error(_("Can't append to folder: %s"), strerror(errno));
-    mx_mbox_close(tmpctx, NULL);
-    FREE(&tmpctx);
+    mx_mbox_close(&tmpctx, NULL);
     goto bail;
   }
 
@@ -234,8 +232,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade
   rc = mx_msg_commit(tmpctx, msg);
   mx_msg_close(tmpctx, &msg);
 
-  mx_mbox_close(tmpctx, NULL);
-  FREE(&tmpctx);
+  mx_mbox_close(&tmpctx, NULL);
 
 bail:
   if (fp)
index 8ebdb24afaafe0d762678dcb651b0abf74407bf3..863dfe2a0517075897357f6942dbe4a9ae55e549 100644 (file)
--- a/mailbox.c
+++ b/mailbox.c
@@ -365,8 +365,7 @@ static int mailbox_mbox_check(struct Mailbox *mailbox, struct stat *sb, bool che
       mailbox->msg_unread = ctx->unread;
       mailbox->msg_flagged = ctx->flagged;
       mailbox->stats_last_checked = ctx->mtime;
-      mx_mbox_close(ctx, NULL);
-      FREE(&ctx);
+      mx_mbox_close(&ctx, NULL);
     }
   }
 
index 75c7061a1ef83d9c98716aacba5feff9e3182a1c..38360fca172d7e7f278c9a7cd0591ceb861ad912 100644 (file)
@@ -809,8 +809,7 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct
       msg = mx_msg_open_new(ctx, hn, is_from(buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM);
       if (!msg)
       {
-        mx_mbox_close(ctx, NULL);
-        FREE(&ctx);
+        mx_mbox_close(&ctx, NULL);
         return -1;
       }
       if ((ctx->magic == MUTT_MBOX) || (ctx->magic == MUTT_MMDF))
@@ -827,8 +826,7 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct
       }
 
       mx_msg_close(ctx, &msg);
-      mx_mbox_close(ctx, NULL);
-      FREE(&ctx);
+      mx_mbox_close(&ctx, NULL);
       return r;
     }
     else
diff --git a/mx.c b/mx.c
index 9618822fed857c53c0b2c405705ead0aba46fa41..009b3b28ebb2bc1453e4443ea7eccbb0c80fad72 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -469,15 +469,13 @@ static int trash_append(struct Context *ctx)
       {
         if (mutt_append_message(ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
         {
-          mx_mbox_close(ctx_trash, NULL);
-          FREE(&ctx_trash);
+          mx_mbox_close(&ctx_trash, NULL);
           return -1;
         }
       }
     }
 
-    mx_mbox_close(ctx_trash, NULL);
-    FREE(&ctx_trash);
+    mx_mbox_close(&ctx_trash, NULL);
   }
   else
   {
@@ -489,26 +487,28 @@ static int trash_append(struct Context *ctx)
 }
 
 /**
- * mx_mbox_close - save changes and close mailbox
+ * mx_mbox_close - Save changes and close mailbox
  * @param ctx        Mailbox
  * @param index_hint Current email
  * @retval  0 Success
  * @retval -1 Failure
  */
-int mx_mbox_close(struct Context *ctx, int *index_hint)
+int mx_mbox_close(struct Context **pctx, int *index_hint)
 {
+  if (!pctx || !*pctx)
+    return 0;
+
+  struct Context *ctx = *pctx;
   int i, move_messages = 0, purge = 1, read_msgs = 0;
   char mbox[PATH_MAX];
   char buf[PATH_MAX + 64];
 
-  if (!ctx)
-    return 0;
-
   ctx->closing = true;
 
   if (ctx->readonly || ctx->dontwrite || ctx->append)
   {
     mx_fastclose_mailbox(ctx);
+    FREE(pctx);
     return 0;
   }
 
@@ -659,16 +659,14 @@ int mx_mbox_close(struct Context *ctx, int *index_hint)
           }
           else
           {
-            mx_mbox_close(f, NULL);
-            FREE(&f);
+            mx_mbox_close(&f, NULL);
             ctx->closing = false;
             return -1;
           }
         }
       }
 
-      mx_mbox_close(f, NULL);
-      FREE(&f);
+      mx_mbox_close(&f, NULL);
     }
   }
   else if (!ctx->changed && ctx->deleted == 0)
@@ -678,6 +676,7 @@ int mx_mbox_close(struct Context *ctx, int *index_hint)
     if (ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF)
       mbox_reset_atime(ctx, NULL);
     mx_fastclose_mailbox(ctx);
+    FREE(pctx);
     return 0;
   }
 
@@ -762,6 +761,7 @@ int mx_mbox_close(struct Context *ctx, int *index_hint)
 #endif
 
   mx_fastclose_mailbox(ctx);
+  FREE(pctx);
 
   return 0;
 }
diff --git a/mx.h b/mx.h
index f69e3ba68221f6313d4d2539ae462dbef12c2dd2..ae19d04ec6d0f899b0dc137b46e59000f939789d 100644 (file)
--- a/mx.h
+++ b/mx.h
@@ -229,7 +229,7 @@ struct MxOps
 
 /* Wrappers for the Mailbox API, see MxOps */
 int             mx_mbox_check  (struct Context *ctx, int *index_hint);
-int             mx_mbox_close  (struct Context *ctx, int *index_hint);
+int             mx_mbox_close  (struct Context **pctx, int *index_hint);
 struct Context *mx_mbox_open   (const char *path, int flags);
 int             mx_mbox_sync   (struct Context *ctx, int *index_hint);
 int             mx_msg_close   (struct Context *ctx, struct Message **msg);
index d39ad4a9ea12c6881ddd0d34a777d284bca23119..8e34ded73a8c01df7a4b93746b3f7f4fcd594070 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -1010,8 +1010,7 @@ void pop_fetch_mail(void)
 
     if (ret == -1)
     {
-      mx_mbox_close(ctx, NULL);
-      FREE(&ctx);
+      mx_mbox_close(&ctx, NULL);
       goto fail;
     }
     if (ret == -2)
@@ -1032,8 +1031,7 @@ void pop_fetch_mail(void)
                  msgbuf, i - last, msgs - last);
   }
 
-  mx_mbox_close(ctx, NULL);
-  FREE(&ctx);
+  mx_mbox_close(&ctx, NULL);
 
   if (rset)
   {
index 80a7aee8583aff1c1ffdee7edb1d8215f737b6f0..28de7cd28c08aec0927dbbae657ee653b9dec1c7 100644 (file)
@@ -301,8 +301,7 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr,
   if (!PostContext->msgcount)
   {
     PostCount = 0;
-    mx_mbox_close(PostContext, NULL);
-    FREE(&PostContext);
+    mx_mbox_close(&PostContext, NULL);
     mutt_error(_("No postponed messages"));
     return -1;
   }
@@ -314,8 +313,7 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr,
   }
   else if (!(h = select_msg()))
   {
-    mx_mbox_close(PostContext, NULL);
-    FREE(&PostContext);
+    mx_mbox_close(&PostContext, NULL);
     return -1;
   }
 
@@ -336,11 +334,9 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr,
   /* avoid the "purge deleted messages" prompt */
   opt_delete = Delete;
   Delete = MUTT_YES;
-  mx_mbox_close(PostContext, NULL);
+  mx_mbox_close(&PostContext, NULL);
   Delete = opt_delete;
 
-  FREE(&PostContext);
-
   struct ListNode *np, *tmp;
   STAILQ_FOREACH_SAFE(np, &hdr->env->userhdrs, entries, tmp)
   {
index 18424d623630eee5bf353ecb1045cb8e9451a440..ad48d3a19a8246146b574d45f3473d72b5f72fdb 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -3193,8 +3193,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid,
     if (!tempfp)
     {
       mutt_perror(tempfile);
-      mx_mbox_close(f, NULL);
-      FREE(&f);
+      mx_mbox_close(&f, NULL);
       goto done;
     }
     /* remember new mail status before appending message */
@@ -3210,8 +3209,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid,
   if (!msg)
   {
     mutt_file_fclose(&tempfp);
-    mx_mbox_close(f, NULL);
-    FREE(&f);
+    mx_mbox_close(&f, NULL);
     goto done;
   }
 
@@ -3329,8 +3327,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid,
       unlink(tempfile);
       mx_msg_commit(f, msg); /* XXX really? */
       mx_msg_close(f, &msg);
-      mx_mbox_close(f, NULL);
-      FREE(&f);
+      mx_mbox_close(&f, NULL);
       goto done;
     }
 
@@ -3361,8 +3358,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid,
   else if (finalpath)
     *finalpath = mutt_str_strdup(msg->committed_path);
   mx_msg_close(f, &msg);
-  mx_mbox_close(f, NULL);
-  FREE(&f);
+  mx_mbox_close(&f, NULL);
 
   if (!post && need_mailbox_cleanup)
     mutt_mailbox_cleanup(path, &st);