1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-17 15:05:02 -05:00

pingpong: remove a malloc per Curl_pp_vsendf call

This typically makes 7-9 fewer mallocs per FTP transfer.

Closes #5997
This commit is contained in:
Daniel Stenberg 2020-09-22 16:26:50 +02:00
parent 3d64031fa7
commit 0548ecaf6a
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -162,9 +162,10 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
const char *fmt, const char *fmt,
va_list args) va_list args)
{ {
ssize_t bytes_written; ssize_t bytes_written = 0;
size_t write_len; size_t write_len;
char *fmt_crlf; char fmt_crlf[128];
size_t fmtlen;
char *s; char *s;
CURLcode result; CURLcode result;
struct connectdata *conn = pp->conn; struct connectdata *conn = pp->conn;
@ -184,16 +185,17 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
data = conn->data; data = conn->data;
fmt_crlf = aprintf("%s\r\n", fmt); /* append a trailing CRLF */ fmtlen = strlen(fmt);
if(!fmt_crlf) DEBUGASSERT(fmtlen < sizeof(fmt_crlf)-3);
return CURLE_OUT_OF_MEMORY; if(fmtlen >= sizeof(fmt_crlf)-3)
return CURLE_BAD_FUNCTION_ARGUMENT;
s = vaprintf(fmt_crlf, args); /* trailing CRLF appended */ memcpy(fmt_crlf, fmt, fmtlen);
free(fmt_crlf); /* append a trailing CRLF+null to the format string */
memcpy(&fmt_crlf[fmtlen], "\r\n", 3);
s = vaprintf(fmt_crlf, args);
if(!s) if(!s)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
bytes_written = 0;
write_len = strlen(s); write_len = strlen(s);
Curl_pp_init(pp); Curl_pp_init(pp);