]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
cleanup: use dprintf earlier to avoid temporary memory allocation
authorBaptiste Daroussin <bapt@FreeBSD.org>
Tue, 2 Nov 2021 14:26:59 +0000 (15:26 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 3 Nov 2021 13:10:28 +0000 (14:10 +0100)
src/send_digest.c

index 4c38d69661e53500b1e4c7c1989acb7aadedc37e..6535d32dc3061487c89acc6431a8667b651635c5 100644 (file)
@@ -399,17 +399,15 @@ errdighdrs:
 
        if ((txt != NULL) && !statctrl(list, "nodigesttext")) {
 
-               tmp = concatstr(3, "\n--", boundary,
-                               "\nContent-Type: text/plain; charset=UTF-8"
-                               "\nContent-Transfer-Encoding: 8bit"
-                               "\n\n");
-               if (dprintf(fd, "%s", tmp) == -1) {
+               if (dprintf(fd, "\n--%s"
+                       "\nContent-Type: text/plain; charset=UTF-8"
+                       "\nContent-Transfer-Encoding: 8bit"
+                       "\n\n", boundary) == -1) {
                        log_error(LOG_ARGS, "Could not write digest text/plain"
                                        " part headers to '%s'", queuename);
                        close(fd);
                        unlink(queuename);
                        myfree(boundary);
-                       myfree(tmp);
                        myfree(queuename);
                        if (txt != NULL) {
                                close_text(txt);
@@ -417,7 +415,6 @@ errdighdrs:
                        }
                        return -1;
                }
-               myfree(tmp);
 
                for (;;) {
                        line = get_processed_text_line(txt, 0, list);
@@ -452,12 +449,10 @@ errdighdrs:
                if (archivefd < 0)
                        continue;
                
-               tmp = concatstr(7, "\n--", boundary,
-                               "\nContent-Type: message/rfc822"
-                               "\nContent-Disposition: inline; filename=\"",
-                                       list->name, "_", buf, ".eml\""
-                               "\n\n");
-               if (dprintf(fd, "%s", tmp) == -1) {
+               if (dprintf(fd, "\n--%s"
+                       "\nContent-Type: message/rfc822"
+                       "\nContent-Disposition: inline; filename=\"%s_%s.eml\"",
+                       boundary, list->name, buf) == -1) {
                        log_error(LOG_ARGS, "Could not write digest part "
                                        "headers for archive index %d to "
                                        "'%s'", i, queuename);
@@ -465,11 +460,9 @@ errdighdrs:
                        close(archivefd);
                        unlink(queuename);
                        myfree(boundary);
-                       myfree(tmp);
                        myfree(queuename);
                        return -1;
                }
-               myfree(tmp);
 
                if (dumpfd2fd(archivefd, fd) < 0) {
                        log_error(LOG_ARGS, "Could not write digest part %d "