mirror of
https://github.com/curl/curl.git
synced 2025-09-27 22:47:00 +03:00
parse_proxy: simply memory handling
... by making sure that the string is always freed after the invoke as parse_proxy will always copy the data and this way there's a single free() instead of multiple ones.
This commit is contained in:
parent
ecc93caaeb
commit
7ed25fcc5c
23
lib/url.c
23
lib/url.c
|
@ -4224,22 +4224,18 @@ static CURLcode parse_proxy(struct SessionHandle *data,
|
||||||
|
|
||||||
if(CURLE_OK == res) {
|
if(CURLE_OK == res) {
|
||||||
conn->bits.proxy_user_passwd = TRUE; /* enable it */
|
conn->bits.proxy_user_passwd = TRUE; /* enable it */
|
||||||
atsign = strdup(atsign+1); /* the right side of the @-letter */
|
atsign++; /* the right side of the @-letter */
|
||||||
|
|
||||||
if(atsign) {
|
if(atsign)
|
||||||
free(proxy); /* free the former proxy string */
|
|
||||||
proxy = proxyptr = atsign; /* now use this instead */
|
proxy = proxyptr = atsign; /* now use this instead */
|
||||||
}
|
|
||||||
else
|
else
|
||||||
res = CURLE_OUT_OF_MEMORY;
|
res = CURLE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(res) {
|
if(res)
|
||||||
free(proxy); /* free the allocated proxy string */
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* start scanning for port number at this point */
|
/* start scanning for port number at this point */
|
||||||
portptr = proxyptr;
|
portptr = proxyptr;
|
||||||
|
@ -4271,20 +4267,17 @@ static CURLcode parse_proxy(struct SessionHandle *data,
|
||||||
conn->port = strtol(prox_portno, NULL, 10);
|
conn->port = strtol(prox_portno, NULL, 10);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(proxyptr[0]=='/') {
|
if(proxyptr[0]=='/')
|
||||||
/* If the first character in the proxy string is a slash, fail
|
/* If the first character in the proxy string is a slash, fail
|
||||||
immediately. The following code will otherwise clear the string which
|
immediately. The following code will otherwise clear the string which
|
||||||
will lead to code running as if no proxy was set! */
|
will lead to code running as if no proxy was set! */
|
||||||
free(proxy); /* free the former proxy string */
|
|
||||||
return CURLE_COULDNT_RESOLVE_PROXY;
|
return CURLE_COULDNT_RESOLVE_PROXY;
|
||||||
}
|
|
||||||
|
|
||||||
/* without a port number after the host name, some people seem to use
|
/* without a port number after the host name, some people seem to use
|
||||||
a slash so we strip everything from the first slash */
|
a slash so we strip everything from the first slash */
|
||||||
atsign = strchr(proxyptr, '/');
|
atsign = strchr(proxyptr, '/');
|
||||||
if(atsign) {
|
if(atsign)
|
||||||
*atsign = 0x0; /* cut off path part from host name */
|
*atsign = 0x0; /* cut off path part from host name */
|
||||||
}
|
|
||||||
|
|
||||||
if(data->set.proxyport)
|
if(data->set.proxyport)
|
||||||
/* None given in the proxy string, then get the default one if it is
|
/* None given in the proxy string, then get the default one if it is
|
||||||
|
@ -4296,7 +4289,6 @@ static CURLcode parse_proxy(struct SessionHandle *data,
|
||||||
conn->proxy.rawalloc = strdup(proxyptr);
|
conn->proxy.rawalloc = strdup(proxyptr);
|
||||||
conn->proxy.name = conn->proxy.rawalloc;
|
conn->proxy.name = conn->proxy.rawalloc;
|
||||||
|
|
||||||
free(proxy);
|
|
||||||
if(!conn->proxy.rawalloc)
|
if(!conn->proxy.rawalloc)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
@ -4927,8 +4919,9 @@ static CURLcode create_conn(struct SessionHandle *data,
|
||||||
if(proxy) {
|
if(proxy) {
|
||||||
result = parse_proxy(data, conn, proxy);
|
result = parse_proxy(data, conn, proxy);
|
||||||
|
|
||||||
/* parse_proxy has freed the proxy string, so don't try to use it again */
|
free(proxy); /* parse_proxy copies the proxy string */
|
||||||
if(result != CURLE_OK)
|
|
||||||
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
if((conn->proxytype == CURLPROXY_HTTP) ||
|
if((conn->proxytype == CURLPROXY_HTTP) ||
|
||||||
|
|
Loading…
Reference in New Issue
Block a user