upload: allocate upload buffer on-demand

Saves 16KB on the easy handle for operations that don't need that
buffer.

Part 1 of #2888
This commit is contained in:
Daniel Stenberg 2018-08-17 00:49:37 +02:00
parent 4939f36524
commit e6e9b006f7
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
7 changed files with 59 additions and 24 deletions

View file

@ -106,6 +106,16 @@ char *Curl_checkheaders(const struct connectdata *conn,
}
#endif
CURLcode Curl_get_upload_buffer(struct Curl_easy *data)
{
if(!data->state.ulbuf) {
data->state.ulbuf = malloc(data->set.upload_buffer_size);
if(!data->state.ulbuf)
return CURLE_OUT_OF_MEMORY;
}
return CURLE_OK;
}
/*
* This function will call the read callback to fill our buffer with data
* to upload.
@ -914,8 +924,11 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
/* only read more data if there's no upload data already
present in the upload buffer */
if(0 == k->upload_present) {
result = Curl_get_upload_buffer(data);
if(result)
return result;
/* init the "upload from here" pointer */
k->upload_fromhere = data->state.uploadbuffer;
k->upload_fromhere = data->state.ulbuf;
if(!k->upload_done) {
/* HTTP pollution, this should be written nicer to become more
@ -1071,7 +1084,10 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
}
else {
/* we've uploaded that buffer now */
k->upload_fromhere = data->state.uploadbuffer;
result = Curl_get_upload_buffer(data);
if(result)
return result;
k->upload_fromhere = data->state.ulbuf;
k->upload_present = 0; /* no more bytes left */
if(k->upload_done) {