[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 176/411: pingpong: remove a malloc per Curl_pp_vsendf call
From: |
gnunet |
Subject: |
[gnurl] 176/411: pingpong: remove a malloc per Curl_pp_vsendf call |
Date: |
Wed, 13 Jan 2021 01:19:51 +0100 |
This is an automated email from the git hooks/post-receive script.
nikita pushed a commit to branch master
in repository gnurl.
commit 0548ecaf6ac6fd8d81d63048d09ece8dbb715666
Author: Daniel Stenberg <daniel@haxx.se>
AuthorDate: Tue Sep 22 16:26:50 2020 +0200
pingpong: remove a malloc per Curl_pp_vsendf call
This typically makes 7-9 fewer mallocs per FTP transfer.
Closes #5997
---
lib/pingpong.c | 20 +++++++++++---------
1 file 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);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnurl] 128/411: runtests: allow creating files without newlines, (continued)
- [gnurl] 128/411: runtests: allow creating files without newlines, gnunet, 2021/01/12
- [gnurl] 147/411: TODO: add PR reference for native IDN support on macOS, gnunet, 2021/01/12
- [gnurl] 155/411: ftp: get rid of the PPSENDF macro, gnunet, 2021/01/12
- [gnurl] 167/411: parsedate: tune the date to epoch conversion, gnunet, 2021/01/12
- [gnurl] 146/411: tool_help.h: update copyright year range, gnunet, 2021/01/12
- [gnurl] 164/411: docs/MQTT: not experimental anymore, gnunet, 2021/01/12
- [gnurl] 178/411: dynbuf: make *addf() not require extra mallocs, gnunet, 2021/01/12
- [gnurl] 157/411: ftp: avoid risk of reading uninitialized integers, gnunet, 2021/01/12
- [gnurl] 170/411: setopt: return CURLE_BAD_FUNCTION_ARGUMENT on bad argument, gnunet, 2021/01/12
- [gnurl] 185/411: strerror: honor Unicode API choice on Windows, gnunet, 2021/01/12
- [gnurl] 176/411: pingpong: remove a malloc per Curl_pp_vsendf call,
gnunet <=
- [gnurl] 125/411: dynbuf: make sure Curl_dyn_tail() zero terminates, gnunet, 2021/01/12
- [gnurl] 144/411: tool_writeout: protect fputs() from NULL, gnunet, 2021/01/12
- [gnurl] 160/411: --help: strdup the category, gnunet, 2021/01/12
- [gnurl] 165/411: docs/MQTT: remove outdated paaragraphs, gnunet, 2021/01/12
- [gnurl] 175/411: symbian: drop support, gnunet, 2021/01/12
- [gnurl] 152/411: github: use new issue template feature, gnunet, 2021/01/12
- [gnurl] 171/411: http_proxy: do not count proxy headers in the header bytecount, gnunet, 2021/01/12
- [gnurl] 166/411: cmake: remove scary warning, gnunet, 2021/01/12
- [gnurl] 151/411: urlapi: use more Curl_safefree, gnunet, 2021/01/12
- [gnurl] 135/411: curl: make checkpasswd use dynbuf, gnunet, 2021/01/12