diff options
author | Daniel Stenberg <daniel@haxx.se> | 2021-11-05 23:20:14 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-11-06 22:54:08 +0100 |
commit | d3d079c138e8abaedcb0c557bc466e69e6b79b1c (patch) | |
tree | 98cc3a2386582d37be0f3265c833ff61ee43f9b2 /src | |
parent | d1624b94f0a21cefe803b2ccafe40bd71939bf42 (diff) | |
download | curl-d3d079c138e8abaedcb0c557bc466e69e6b79b1c.tar.gz |
tool_operate: fix torture leaks with etags
Spotted by torture testing 343 344 345 347.
Follow-up from cc71d352651a0
Pointed-out-by: Dan Fandrich
Closes #7969
Diffstat (limited to 'src')
-rw-r--r-- | src/tool_operate.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/tool_operate.c b/src/tool_operate.c index 1a1dc6468..835411c6b 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -812,6 +812,7 @@ static CURLcode single_transfer(struct GlobalConfig *global, if(config->etag_compare_file) { char *etag_from_file = NULL; char *header = NULL; + ParameterError pe; /* open file for reading: */ FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT); @@ -840,12 +841,14 @@ static CURLcode single_transfer(struct GlobalConfig *global, } /* add Etag from file to list of custom headers */ - add2list(&config->headers, header); - + pe = add2list(&config->headers, header); Curl_safefree(header); - if(file) { + if(file) fclose(file); + if(pe != PARAM_OK) { + result = CURLE_OUT_OF_MEMORY; + break; } } @@ -874,12 +877,16 @@ static CURLcode single_transfer(struct GlobalConfig *global, } curl = curl_easy_init(); - result = add_per_transfer(&per); + if(curl) + result = add_per_transfer(&per); if(result || !curl) { curl_easy_cleanup(curl); + if(etag_save->stream) + fclose(etag_save->stream); result = CURLE_OUT_OF_MEMORY; break; } + per->etag_save = etag_first; /* copy the whole struct */ if(state->uploadfile) { per->uploadfile = strdup(state->uploadfile); if(!per->uploadfile) { @@ -892,7 +899,6 @@ static CURLcode single_transfer(struct GlobalConfig *global, per->config = config; per->curl = curl; per->urlnum = urlnode->num; - per->etag_save = etag_first; /* copy the whole struct */ /* default headers output stream is stdout */ heads = &per->heads; |