altsvc: clone setting in curl_easy_duphandle

The cache content is not duplicated, like other caches, but the setting
and specified file name are.

Test 1908 is extended to verify this somewhat. Since the duplicated
handle gets the same file name, the test unfortunately overwrites the
same file twice (with different contents) which makes it hard to check
automatically.

Closes #5923
This commit is contained in:
Daniel Stenberg 2020-09-05 21:21:26 +02:00
parent 8ca54a03ea
commit f93455eb04
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
7 changed files with 49 additions and 10 deletions

View file

@ -302,11 +302,12 @@ CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl)
* Curl_altsvc_cleanup() frees an altsvc cache instance and all associated
* resources.
*/
void Curl_altsvc_cleanup(struct altsvcinfo *altsvc)
void Curl_altsvc_cleanup(struct altsvcinfo **altsvcp)
{
struct Curl_llist_element *e;
struct Curl_llist_element *n;
if(altsvc) {
if(*altsvcp) {
struct altsvcinfo *altsvc = *altsvcp;
for(e = altsvc->list.head; e; e = n) {
struct altsvc *as = e->ptr;
n = e->next;
@ -314,6 +315,7 @@ void Curl_altsvc_cleanup(struct altsvcinfo *altsvc)
}
free(altsvc->filename);
free(altsvc);
*altsvcp = NULL; /* clear the pointer */
}
}

View file

@ -61,7 +61,7 @@ CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char *file);
CURLcode Curl_altsvc_save(struct Curl_easy *data,
struct altsvcinfo *asi, const char *file);
CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl);
void Curl_altsvc_cleanup(struct altsvcinfo *altsvc);
void Curl_altsvc_cleanup(struct altsvcinfo **altsvc);
CURLcode Curl_altsvc_parse(struct Curl_easy *data,
struct altsvcinfo *altsvc, const char *value,
enum alpnid srcalpn, const char *srchost,
@ -74,5 +74,6 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi,
#else
/* disabled */
#define Curl_altsvc_save(a,b,c)
#define Curl_altsvc_cleanup(x)
#endif /* CURL_DISABLE_HTTP || USE_ALTSVC */
#endif /* HEADER_CURL_ALTSVC_H */

View file

@ -78,6 +78,7 @@
#include "system_win32.h"
#include "http2.h"
#include "dynbuf.h"
#include "altsvc.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@ -883,6 +884,15 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
goto fail;
}
#ifdef USE_ALTSVC
if(data->asi) {
outcurl->asi = Curl_altsvc_init();
if(!outcurl->asi)
goto fail;
if(outcurl->set.str[STRING_ALTSVC])
(void)Curl_altsvc_load(outcurl->asi, outcurl->set.str[STRING_ALTSVC]);
}
#endif
/* Clone the resolver handle, if present, for the new handle */
if(Curl_resolver_duphandle(outcurl,
&outcurl->state.resolver,
@ -930,6 +940,7 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
Curl_dyn_free(&outcurl->state.headerb);
Curl_safefree(outcurl->change.url);
Curl_safefree(outcurl->change.referer);
Curl_altsvc_cleanup(&outcurl->asi);
Curl_freeset(outcurl);
free(outcurl);
}

View file

@ -391,11 +391,8 @@ CURLcode Curl_close(struct Curl_easy **datap)
Curl_dyn_free(&data->state.headerb);
Curl_safefree(data->state.ulbuf);
Curl_flush_cookies(data, TRUE);
#ifdef USE_ALTSVC
Curl_altsvc_save(data, data->asi, data->set.str[STRING_ALTSVC]);
Curl_altsvc_cleanup(data->asi);
data->asi = NULL;
#endif
Curl_altsvc_cleanup(&data->asi);
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
Curl_http_auth_cleanup_digest(data);
#endif