mirror of
https://github.com/curl/curl.git
synced 2026-08-24 13:23:33 +03:00
schannel: reuse the send buffer
- Reuse a buffer for schannel_send instead of allocating and freeing a buffer for every send. Closes https://github.com/curl/curl/pull/22540
This commit is contained in:
parent
a61f2f9219
commit
419f6404d4
2 changed files with 15 additions and 6 deletions
|
|
@ -1996,13 +1996,18 @@ static CURLcode schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|||
len = backend->stream_sizes.cbMaximumMessage;
|
||||
}
|
||||
|
||||
/* calculate the complete message length and allocate a buffer for it */
|
||||
/* calculate the complete message length and prepare the send buffer */
|
||||
data_len = backend->stream_sizes.cbHeader + len +
|
||||
backend->stream_sizes.cbTrailer;
|
||||
ptr = curlx_malloc(data_len);
|
||||
if(!ptr) {
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
if(data_len > backend->send_buffer_len) {
|
||||
ptr = curlx_realloc(backend->send_buffer, data_len);
|
||||
if(!ptr)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
backend->send_buffer = ptr;
|
||||
backend->send_buffer_len = data_len;
|
||||
}
|
||||
else
|
||||
ptr = backend->send_buffer;
|
||||
|
||||
/* setup output buffers (header, data, trailer, empty) */
|
||||
InitSecBuffer(&outbuf[0], SECBUFFER_STREAM_HEADER,
|
||||
|
|
@ -2091,8 +2096,6 @@ static CURLcode schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|||
result = CURLE_SEND_ERROR;
|
||||
}
|
||||
|
||||
curlx_safefree(ptr);
|
||||
|
||||
if(len == *pnwritten)
|
||||
/* Encrypted message including header, data and trailer entirely sent.
|
||||
The return value is the number of unencrypted bytes that were sent. */
|
||||
|
|
@ -2567,6 +2570,10 @@ static void schannel_close(struct Curl_cfilter *cf, struct Curl_easy *data)
|
|||
backend->cred = NULL;
|
||||
}
|
||||
|
||||
/* free the buffer used to encrypt outgoing data */
|
||||
curlx_safefree(backend->send_buffer);
|
||||
backend->send_buffer_len = 0;
|
||||
|
||||
/* free internal buffer for received encrypted data */
|
||||
if(backend->encdata.buffer) {
|
||||
curlx_safefree(backend->encdata.buffer);
|
||||
|
|
|
|||
|
|
@ -112,6 +112,8 @@ struct sbuffer {
|
|||
};
|
||||
|
||||
struct schannel_ssl_backend_data {
|
||||
unsigned char *send_buffer;
|
||||
size_t send_buffer_len;
|
||||
struct sbuffer encdata;
|
||||
struct sbuffer decdata;
|
||||
struct Curl_schannel_cred *cred;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue