From f2acd76de5d905dcad9fdf8679add9481d908fd4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 5 Nov 2021 23:20:14 +0100 Subject: tool_operate: fix torture leaks with etags Spotted by torture testing 343 344 345 347. Follow-up from cc71d352651a0 Pointed-out-by: Dan Fandrich --- src/tool_operate.c | 16 +++++++++++----- 1 file 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; -- cgit v1.2.1