]> granicus.if.org Git - mutt/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)
committerKevin McCarthy <kevin@8t8.us>
Wed, 23 Oct 2019 08:03:56 +0000 (16:03 +0800)
recvcmd.c

index c880d53e4a91337633247cf2cc44718ef43d3ade..9bf3c3b0a7128bb724a5d526ebbb8e457bcb46fa 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -880,8 +880,8 @@ void mutt_attach_reply (FILE * fp, HEADER * hdr,
   short i;
 
   STATE st;
-  char tmpbody[_POSIX_PATH_MAX];
-  FILE *tmpfp;
+  BUFFER *tmpbody = NULL;
+  FILE *tmpfp = NULL;
 
   char prefix[SHORT_STRING];
   int rc;
@@ -917,17 +917,14 @@ void mutt_attach_reply (FILE * fp, HEADER * hdr,
 
   if (attach_reply_envelope_defaults (tmphdr->env, actx,
                                      parent_hdr ? parent_hdr : (cur ? cur->hdr : NULL), flags) == -1)
-  {
-    mutt_free_header (&tmphdr);
-    return;
-  }
+    goto cleanup;
 
-  mutt_mktemp (tmpbody, sizeof (tmpbody));
-  if ((tmpfp = safe_fopen (tmpbody, "w")) == NULL)
+  tmpbody = mutt_buffer_pool_get ();
+  mutt_buffer_mktemp (tmpbody);
+  if ((tmpfp = safe_fopen (mutt_b2s (tmpbody), "w")) == NULL)
   {
-    mutt_error (_("Can't create %s."), tmpbody);
-    mutt_free_header (&tmphdr);
-    return;
+    mutt_error (_("Can't create %s."), mutt_b2s (tmpbody));
+    goto cleanup;
   }
 
   if (!parent_hdr)
@@ -994,15 +991,24 @@ void mutt_attach_reply (FILE * fp, HEADER * hdr,
     if (mime_reply_any && !cur &&
        copy_problematic_attachments (&tmphdr->content, actx, 0) == NULL)
     {
-      mutt_free_header (&tmphdr);
-      safe_fclose (&tmpfp);
-      return;
+      goto cleanup;
     }
   }
 
   safe_fclose (&tmpfp);
 
-  if (ci_send_message (flags, tmphdr, tmpbody, NULL,
+  if (ci_send_message (flags, tmphdr, mutt_b2s (tmpbody), NULL,
                        parent_hdr ? parent_hdr : (cur ? cur->hdr : NULL)) == 0)
     mutt_set_flag (Context, hdr, MUTT_REPLIED, 1);
+
+  tmphdr = NULL;  /* ci_send_message frees this */
+
+cleanup:
+  if (tmpfp)
+  {
+    safe_fclose (&tmpfp);
+    mutt_unlink (mutt_b2s (tmpbody));
+  }
+  mutt_buffer_pool_release (&tmpbody);
+  mutt_free_header (&tmphdr);
 }