mirror of
https://github.com/moparisthebest/curl
synced 2024-12-23 16:48:49 -05:00
curl: fix memory leak in OOM in etags logic
Detected by torture tests Closes #4706
This commit is contained in:
parent
4940bb8568
commit
70a6541515
@ -926,25 +926,25 @@ static CURLcode single_transfer(struct GlobalConfig *global,
|
|||||||
/* open file for reading: */
|
/* open file for reading: */
|
||||||
FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT);
|
FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT);
|
||||||
if(!file) {
|
if(!file) {
|
||||||
warnf(
|
errorf(config->global,
|
||||||
config->global,
|
"Failed to open %s\n", config->etag_compare_file);
|
||||||
"Failed to open %s\n", config->etag_compare_file);
|
|
||||||
|
|
||||||
result = CURLE_READ_ERROR;
|
result = CURLE_READ_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((PARAM_OK == file2string(&etag_from_file, file)) &&
|
if((PARAM_OK == file2string(&etag_from_file, file)) &&
|
||||||
etag_from_file)
|
etag_from_file) {
|
||||||
header = aprintf("If-None-Match: \"%s\"", etag_from_file);
|
header = aprintf("If-None-Match: \"%s\"", etag_from_file);
|
||||||
|
Curl_safefree(etag_from_file);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
header = aprintf("If-None-Match: \"\"");
|
header = aprintf("If-None-Match: \"\"");
|
||||||
|
|
||||||
if(!header) {
|
if(!header) {
|
||||||
warnf(
|
if(file)
|
||||||
config->global,
|
fclose(file);
|
||||||
"Failed to allocate memory for custom etag header\n");
|
errorf(config->global,
|
||||||
|
"Failed to allocate memory for custom etag header\n");
|
||||||
result = CURLE_OUT_OF_MEMORY;
|
result = CURLE_OUT_OF_MEMORY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -953,7 +953,6 @@ static CURLcode single_transfer(struct GlobalConfig *global,
|
|||||||
add2list(&config->headers, header);
|
add2list(&config->headers, header);
|
||||||
|
|
||||||
Curl_safefree(header);
|
Curl_safefree(header);
|
||||||
Curl_safefree(etag_from_file);
|
|
||||||
|
|
||||||
if(file) {
|
if(file) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
Loading…
Reference in New Issue
Block a user