From: Kevin McCarthy Date: Wed, 23 Oct 2019 08:03:56 +0000 (+0800) Subject: Convert mutt_attach_reply() to use buffer pool. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6380cbd6b9450ab542df2eafaade12059eed8618;p=mutt Convert mutt_attach_reply() to use buffer pool. --- diff --git a/recvcmd.c b/recvcmd.c index c880d53e..9bf3c3b0 100644 --- 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); }