summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-09-22 16:26:50 +0200
committerDaniel Stenberg <daniel@haxx.se>2020-09-22 16:49:59 +0200
commitf419cad8205d7d6f1300b082124fe04ec0fb994f (patch)
treeef6e3001bb32236511d1d0db70605977fa38d923
parent3d64031fa7a80ac4ae3fd09a5939196268b92f81 (diff)
downloadcurl-bagder/pingpong-send-less-malloc.tar.gz
pingpong: remove a malloc per Curl_pp_vsendf callbagder/pingpong-send-less-malloc
This typically makes 7-9 fewer mallocs per FTP transfer.
-rw-r--r--lib/pingpong.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/pingpong.c b/lib/pingpong.c
index 314331521..1cfd0286e 100644
--- a/lib/pingpong.c
+++ b/lib/pingpong.c
@@ -162,9 +162,10 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
const char *fmt,
va_list args)
{
- ssize_t bytes_written;
+ ssize_t bytes_written = 0;
size_t write_len;
- char *fmt_crlf;
+ char fmt_crlf[128];
+ size_t fmtlen;
char *s;
CURLcode result;
struct connectdata *conn = pp->conn;
@@ -184,16 +185,17 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
data = conn->data;
- fmt_crlf = aprintf("%s\r\n", fmt); /* append a trailing CRLF */
- if(!fmt_crlf)
- return CURLE_OUT_OF_MEMORY;
-
- s = vaprintf(fmt_crlf, args); /* trailing CRLF appended */
- free(fmt_crlf);
+ fmtlen = strlen(fmt);
+ DEBUGASSERT(fmtlen < sizeof(fmt_crlf)-3);
+ if(fmtlen >= sizeof(fmt_crlf)-3)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ memcpy(fmt_crlf, fmt, fmtlen);
+ /* append a trailing CRLF+null to the format string */
+ memcpy(&fmt_crlf[fmtlen], "\r\n", 3);
+ s = vaprintf(fmt_crlf, args);
if(!s)
return CURLE_OUT_OF_MEMORY;
- bytes_written = 0;
write_len = strlen(s);
Curl_pp_init(pp);