From: Daniel Stenberg Date: Wed, 16 Jul 2025 22:06:55 +0000 (+0200) Subject: tool_operate: avoid superfluous strdup'ing output X-Git-Tag: curl-8_16_0~453 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e44631d9c0632bae42d85af3831cc2155066975;p=thirdparty%2Fcurl.git tool_operate: avoid superfluous strdup'ing output Closes #17946 --- diff --git a/src/tool_operate.c b/src/tool_operate.c index 32858f1141..7abad907bc 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -351,7 +351,7 @@ void single_transfer_cleanup(struct OperationConfig *config) struct State *state = &config->state; /* Free list of remaining URLs */ glob_cleanup(&state->urls); - tool_safefree(state->outfiles); + state->outfiles = NULL; tool_safefree(state->uploadfile); /* Free list of globbed upload files */ glob_cleanup(&state->inglob); @@ -865,7 +865,7 @@ static CURLcode etag_store(struct OperationConfig *config, struct State *state = &config->state; warnf(config->global, "Failed creating file for saving etags: \"%s\". " "Skip this transfer", config->etag_save_file); - tool_safefree(state->outfiles); + state->outfiles = NULL; glob_cleanup(&state->urls); *skip = TRUE; return CURLE_OK; @@ -1169,14 +1169,8 @@ static CURLcode single_transfer(struct OperationConfig *config, } /* save outfile pattern before expansion */ - if(urlnode->outfile && !state->outfiles) { - state->outfiles = strdup(urlnode->outfile); - if(!state->outfiles) { - errorf(global, "out of memory"); - result = CURLE_OUT_OF_MEMORY; - break; - } - } + if(urlnode->outfile && !state->outfiles) + state->outfiles = urlnode->outfile; if(!config->globoff && urlnode->infile && !state->inglob) { /* Unless explicitly shut off */ @@ -1422,7 +1416,7 @@ static CURLcode single_transfer(struct OperationConfig *config, glob_cleanup(&state->urls); state->urlnum = 0; - tool_safefree(state->outfiles); + state->outfiles = NULL; tool_safefree(state->uploadfile); /* Free list of globbed upload files */ glob_cleanup(&state->inglob); @@ -1431,7 +1425,7 @@ static CURLcode single_transfer(struct OperationConfig *config, } break; } - tool_safefree(state->outfiles); + state->outfiles = NULL; fail: if(!*added || result) { *added = FALSE;