tool_operate: avoid superfluous strdup'ing output

Closes #17946
This commit is contained in:
Daniel Stenberg 2025-07-17 00:06:55 +02:00
parent cfbfb65047
commit 6e44631d9c
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -351,7 +351,7 @@ void single_transfer_cleanup(struct OperationConfig *config)
struct State *state = &config->state; struct State *state = &config->state;
/* Free list of remaining URLs */ /* Free list of remaining URLs */
glob_cleanup(&state->urls); glob_cleanup(&state->urls);
tool_safefree(state->outfiles); state->outfiles = NULL;
tool_safefree(state->uploadfile); tool_safefree(state->uploadfile);
/* Free list of globbed upload files */ /* Free list of globbed upload files */
glob_cleanup(&state->inglob); glob_cleanup(&state->inglob);
@ -865,7 +865,7 @@ static CURLcode etag_store(struct OperationConfig *config,
struct State *state = &config->state; struct State *state = &config->state;
warnf(config->global, "Failed creating file for saving etags: \"%s\". " warnf(config->global, "Failed creating file for saving etags: \"%s\". "
"Skip this transfer", config->etag_save_file); "Skip this transfer", config->etag_save_file);
tool_safefree(state->outfiles); state->outfiles = NULL;
glob_cleanup(&state->urls); glob_cleanup(&state->urls);
*skip = TRUE; *skip = TRUE;
return CURLE_OK; return CURLE_OK;
@ -1169,14 +1169,8 @@ static CURLcode single_transfer(struct OperationConfig *config,
} }
/* save outfile pattern before expansion */ /* save outfile pattern before expansion */
if(urlnode->outfile && !state->outfiles) { if(urlnode->outfile && !state->outfiles)
state->outfiles = strdup(urlnode->outfile); state->outfiles = urlnode->outfile;
if(!state->outfiles) {
errorf(global, "out of memory");
result = CURLE_OUT_OF_MEMORY;
break;
}
}
if(!config->globoff && urlnode->infile && !state->inglob) { if(!config->globoff && urlnode->infile && !state->inglob) {
/* Unless explicitly shut off */ /* Unless explicitly shut off */
@ -1422,7 +1416,7 @@ static CURLcode single_transfer(struct OperationConfig *config,
glob_cleanup(&state->urls); glob_cleanup(&state->urls);
state->urlnum = 0; state->urlnum = 0;
tool_safefree(state->outfiles); state->outfiles = NULL;
tool_safefree(state->uploadfile); tool_safefree(state->uploadfile);
/* Free list of globbed upload files */ /* Free list of globbed upload files */
glob_cleanup(&state->inglob); glob_cleanup(&state->inglob);
@ -1431,7 +1425,7 @@ static CURLcode single_transfer(struct OperationConfig *config,
} }
break; break;
} }
tool_safefree(state->outfiles); state->outfiles = NULL;
fail: fail:
if(!*added || result) { if(!*added || result) {
*added = FALSE; *added = FALSE;