mirror of
https://github.com/curl/curl.git
synced 2026-08-25 01:03:31 +03:00
altsvc: keep a copy of the file name to survive handle reset
The alt-svc cache survives a call to curl_easy_reset fine, but the file name to use for saving the cache was cleared. Now the alt-svc cache has a copy of the file name to survive handle resets. Added test 1908 to verify. Reported-by: Craig Andrews Fixes #4898 Closes #4902
This commit is contained in:
parent
f8f4a94465
commit
02f8de6516
6 changed files with 143 additions and 4 deletions
17
lib/altsvc.c
17
lib/altsvc.c
|
|
@ -185,7 +185,16 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file)
|
|||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
char *line = NULL;
|
||||
FILE *fp = fopen(file, FOPEN_READTEXT);
|
||||
FILE *fp;
|
||||
|
||||
/* we need a private copy of the file name so that the altsvc cache file
|
||||
name survives an easy handle reset */
|
||||
free(asi->filename);
|
||||
asi->filename = strdup(file);
|
||||
if(!asi->filename)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
fp = fopen(file, FOPEN_READTEXT);
|
||||
if(fp) {
|
||||
line = malloc(MAX_ALTSVC_LINE);
|
||||
if(!line)
|
||||
|
|
@ -206,6 +215,7 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file)
|
|||
return result;
|
||||
|
||||
fail:
|
||||
Curl_safefree(asi->filename);
|
||||
free(line);
|
||||
fclose(fp);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -299,6 +309,7 @@ void Curl_altsvc_cleanup(struct altsvcinfo *altsvc)
|
|||
n = e->next;
|
||||
altsvc_free(as);
|
||||
}
|
||||
free(altsvc->filename);
|
||||
free(altsvc);
|
||||
}
|
||||
}
|
||||
|
|
@ -317,6 +328,10 @@ CURLcode Curl_altsvc_save(struct altsvcinfo *altsvc, const char *file)
|
|||
/* no cache activated */
|
||||
return CURLE_OK;
|
||||
|
||||
/* if not new name is given, use the one we stored from the load */
|
||||
if(!file && altsvc->filename)
|
||||
file = altsvc->filename;
|
||||
|
||||
if((altsvc->flags & CURLALTSVC_READONLYFILE) || !file || !file[0])
|
||||
/* marked as read-only, no file or zero length file name */
|
||||
return CURLE_OK;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue