]> granicus.if.org Git - neomutt/commitdiff
Convert mutt_attach_reply() to use buffer pool
authorKevin McCarthy <kevin@8t8.us>
Wed, 23 Oct 2019 08:03:56 +0000 (16:03 +0800)
committerRichard Russon <rich@flatcap.org>
Sat, 26 Oct 2019 22:55:44 +0000 (23:55 +0100)
Upstream-commit: https://gitlab.com/muttmua/mutt/commit/6380cbd6b9450ab542df2eafaade12059eed8618
Co-authored-by: Richard Russon <rich@flatcap.org>
recvcmd.c

index 65878ba2e4dcde36fb576e8d2ef635aafb994f22..8fe30e13ca4cfd4f8a86a70225779387286a00c6 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -910,10 +910,9 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx,
   struct Email *e_parent = NULL;
   FILE *fp_parent = NULL;
   struct Email *e_tmp = NULL;
-
   struct State st;
-  char tmpbody[PATH_MAX];
   FILE *fp_tmp = NULL;
+  struct Buffer *tmpbody = NULL;
 
   char prefix[128];
 
@@ -959,17 +958,16 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx,
   if (attach_reply_envelope_defaults(
           e_tmp->env, actx, e_parent ? e_parent : (e_cur ? e_cur->email : NULL), flags) == -1)
   {
-    email_free(&e_tmp);
-    return;
+    goto cleanup;
   }
 
-  mutt_mktemp(tmpbody, sizeof(tmpbody));
-  fp_tmp = mutt_file_fopen(tmpbody, "w");
+  tmpbody = mutt_buffer_pool_get();
+  mutt_buffer_mktemp(tmpbody);
+  fp_tmp = mutt_file_fopen(mutt_b2s(tmpbody), "w");
   if (!fp_tmp)
   {
-    mutt_error(_("Can't create %s"), tmpbody);
-    email_free(&e_tmp);
-    return;
+    mutt_error(_("Can't create %s"), mutt_b2s(tmpbody));
+    goto cleanup;
   }
 
   if (!e_parent)
@@ -1038,9 +1036,7 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx,
     if (mime_reply_any && !e_cur &&
         !copy_problematic_attachments(&e_tmp->content, actx, false))
     {
-      email_free(&e_tmp);
-      mutt_file_fclose(&fp_tmp);
-      return;
+      goto cleanup;
     }
   }
 
@@ -1048,10 +1044,20 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx,
 
   struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
   el_add_email(&el, e_parent ? e_parent : (e_cur ? e_cur->email : NULL));
-  if (ci_send_message(flags, e_tmp, tmpbody, NULL, &el) == 0)
+  if (ci_send_message(flags, e_tmp, mutt_b2s(tmpbody), NULL, &el) == 0)
   {
     mutt_set_flag(Context->mailbox, e, MUTT_REPLIED, true);
   }
+  e_tmp = NULL; /* ci_send_message frees this */
+
+cleanup:
+  if (fp_tmp)
+  {
+    mutt_file_fclose(&fp_tmp);
+    mutt_file_unlink(mutt_b2s(tmpbody));
+  }
+  mutt_buffer_pool_release(&tmpbody);
+  email_free(&e_tmp);
   emaillist_clear(&el);
 }