mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
OOM handling/cleanup slight adjustments
This commit is contained in:
parent
584dc8b8af
commit
bff78cc18e
@ -701,10 +701,10 @@ void curl_easy_reset(CURL *curl)
|
|||||||
struct SessionHandle *data = (struct SessionHandle *)curl;
|
struct SessionHandle *data = (struct SessionHandle *)curl;
|
||||||
|
|
||||||
Curl_safefree(data->state.pathbuffer);
|
Curl_safefree(data->state.pathbuffer);
|
||||||
data->state.pathbuffer=NULL;
|
|
||||||
|
data->state.path = NULL;
|
||||||
|
|
||||||
Curl_safefree(data->state.proto.generic);
|
Curl_safefree(data->state.proto.generic);
|
||||||
data->state.proto.generic=NULL;
|
|
||||||
|
|
||||||
/* zero out UserDefined data: */
|
/* zero out UserDefined data: */
|
||||||
Curl_freeset(data);
|
Curl_freeset(data);
|
||||||
|
@ -3667,8 +3667,7 @@ static CURLcode wc_statemach(struct connectdata *conn)
|
|||||||
strcat(tmp_path, finfo->filename);
|
strcat(tmp_path, finfo->filename);
|
||||||
/* switch default "state.pathbuffer" and tmp_path, good to see
|
/* switch default "state.pathbuffer" and tmp_path, good to see
|
||||||
ftp_parse_url_path function to understand this trick */
|
ftp_parse_url_path function to understand this trick */
|
||||||
if(conn->data->state.pathbuffer)
|
Curl_safefree(conn->data->state.pathbuffer);
|
||||||
free(conn->data->state.pathbuffer);
|
|
||||||
conn->data->state.pathbuffer = tmp_path;
|
conn->data->state.pathbuffer = tmp_path;
|
||||||
conn->data->state.path = tmp_path;
|
conn->data->state.path = tmp_path;
|
||||||
|
|
||||||
|
@ -1912,8 +1912,10 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
memcpy(newurl + newlen + (ptr - url),
|
memcpy(newurl + newlen + (ptr - url),
|
||||||
ptr + currlen, /* copy the trailing zero byte too */
|
ptr + currlen, /* copy the trailing zero byte too */
|
||||||
urllen - (ptr-url) - currlen + 1);
|
urllen - (ptr-url) - currlen + 1);
|
||||||
if(data->change.url_alloc)
|
if(data->change.url_alloc) {
|
||||||
free(data->change.url);
|
Curl_safefree(data->change.url);
|
||||||
|
data->change.url_alloc = FALSE;
|
||||||
|
}
|
||||||
data->change.url = newurl;
|
data->change.url = newurl;
|
||||||
data->change.url_alloc = TRUE;
|
data->change.url_alloc = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1806,15 +1806,14 @@ CURLcode Curl_follow(struct SessionHandle *data,
|
|||||||
when we get the next URL. We pick the ->url field, which may or may
|
when we get the next URL. We pick the ->url field, which may or may
|
||||||
not be 100% correct */
|
not be 100% correct */
|
||||||
|
|
||||||
if(data->change.referer_alloc)
|
if(data->change.referer_alloc) {
|
||||||
/* If we already have an allocated referer, free this first */
|
Curl_safefree(data->change.referer);
|
||||||
free(data->change.referer);
|
data->change.referer_alloc = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
data->change.referer = strdup(data->change.url);
|
data->change.referer = strdup(data->change.url);
|
||||||
if(!data->change.referer) {
|
if(!data->change.referer)
|
||||||
data->change.referer_alloc = FALSE;
|
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
}
|
|
||||||
data->change.referer_alloc = TRUE; /* yes, free this later */
|
data->change.referer_alloc = TRUE; /* yes, free this later */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1861,12 +1860,13 @@ CURLcode Curl_follow(struct SessionHandle *data,
|
|||||||
if(disallowport)
|
if(disallowport)
|
||||||
data->state.allow_port = FALSE;
|
data->state.allow_port = FALSE;
|
||||||
|
|
||||||
if(data->change.url_alloc)
|
if(data->change.url_alloc) {
|
||||||
free(data->change.url);
|
Curl_safefree(data->change.url);
|
||||||
else
|
data->change.url_alloc = FALSE;
|
||||||
data->change.url_alloc = TRUE; /* the URL is allocated */
|
}
|
||||||
|
|
||||||
data->change.url = newurl;
|
data->change.url = newurl;
|
||||||
|
data->change.url_alloc = TRUE;
|
||||||
newurl = NULL; /* don't free! */
|
newurl = NULL; /* don't free! */
|
||||||
|
|
||||||
infof(data, "Issue another request to this URL: '%s'\n", data->change.url);
|
infof(data, "Issue another request to this URL: '%s'\n", data->change.url);
|
||||||
|
47
lib/url.c
47
lib/url.c
@ -276,10 +276,7 @@ static CURLcode setstropt(char **charp, char * s)
|
|||||||
/* Release the previous storage at `charp' and replace by a dynamic storage
|
/* Release the previous storage at `charp' and replace by a dynamic storage
|
||||||
copy of `s'. Return CURLE_OK or CURLE_OUT_OF_MEMORY. */
|
copy of `s'. Return CURLE_OK or CURLE_OUT_OF_MEMORY. */
|
||||||
|
|
||||||
if(*charp) {
|
Curl_safefree(*charp);
|
||||||
free(*charp);
|
|
||||||
*charp = (char *) NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(s) {
|
if(s) {
|
||||||
s = strdup(s);
|
s = strdup(s);
|
||||||
@ -480,6 +477,8 @@ CURLcode Curl_close(struct SessionHandle *data)
|
|||||||
|
|
||||||
/* Free the pathbuffer */
|
/* Free the pathbuffer */
|
||||||
Curl_safefree(data->state.pathbuffer);
|
Curl_safefree(data->state.pathbuffer);
|
||||||
|
data->state.path = NULL;
|
||||||
|
|
||||||
Curl_safefree(data->state.proto.generic);
|
Curl_safefree(data->state.proto.generic);
|
||||||
|
|
||||||
/* Close down all open SSL info and sessions */
|
/* Close down all open SSL info and sessions */
|
||||||
@ -488,11 +487,17 @@ CURLcode Curl_close(struct SessionHandle *data)
|
|||||||
Curl_safefree(data->state.scratch);
|
Curl_safefree(data->state.scratch);
|
||||||
Curl_ssl_free_certinfo(data);
|
Curl_ssl_free_certinfo(data);
|
||||||
|
|
||||||
if(data->change.referer_alloc)
|
if(data->change.referer_alloc) {
|
||||||
free(data->change.referer);
|
Curl_safefree(data->change.referer);
|
||||||
|
data->change.referer_alloc = FALSE;
|
||||||
|
}
|
||||||
|
data->change.referer = NULL;
|
||||||
|
|
||||||
if(data->change.url_alloc)
|
if(data->change.url_alloc) {
|
||||||
free(data->change.url);
|
Curl_safefree(data->change.url);
|
||||||
|
data->change.url_alloc = FALSE;
|
||||||
|
}
|
||||||
|
data->change.url = NULL;
|
||||||
|
|
||||||
Curl_safefree(data->state.headerbuff);
|
Curl_safefree(data->state.headerbuff);
|
||||||
|
|
||||||
@ -1216,7 +1221,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
|||||||
* String to set in the HTTP Referer: field.
|
* String to set in the HTTP Referer: field.
|
||||||
*/
|
*/
|
||||||
if(data->change.referer_alloc) {
|
if(data->change.referer_alloc) {
|
||||||
free(data->change.referer);
|
Curl_safefree(data->change.referer);
|
||||||
data->change.referer_alloc = FALSE;
|
data->change.referer_alloc = FALSE;
|
||||||
}
|
}
|
||||||
result = setstropt(&data->set.str[STRING_SET_REFERER],
|
result = setstropt(&data->set.str[STRING_SET_REFERER],
|
||||||
@ -1633,7 +1638,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
|||||||
*/
|
*/
|
||||||
if(data->change.url_alloc) {
|
if(data->change.url_alloc) {
|
||||||
/* the already set URL is allocated, free it first! */
|
/* the already set URL is allocated, free it first! */
|
||||||
free(data->change.url);
|
Curl_safefree(data->change.url);
|
||||||
data->change.url_alloc = FALSE;
|
data->change.url_alloc = FALSE;
|
||||||
}
|
}
|
||||||
result = setstropt(&data->set.str[STRING_SET_URL],
|
result = setstropt(&data->set.str[STRING_SET_URL],
|
||||||
@ -4428,8 +4433,10 @@ static CURLcode parse_remote_port(struct SessionHandle *data,
|
|||||||
if(!url)
|
if(!url)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
if(data->change.url_alloc)
|
if(data->change.url_alloc) {
|
||||||
free(data->change.url);
|
Curl_safefree(data->change.url);
|
||||||
|
data->change.url_alloc = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
data->change.url = url;
|
data->change.url = url;
|
||||||
data->change.url_alloc = TRUE;
|
data->change.url_alloc = TRUE;
|
||||||
@ -4653,11 +4660,11 @@ static void reuse_conn(struct connectdata *old_conn,
|
|||||||
|
|
||||||
/* host can change, when doing keepalive with a proxy ! */
|
/* host can change, when doing keepalive with a proxy ! */
|
||||||
if(conn->bits.proxy) {
|
if(conn->bits.proxy) {
|
||||||
free(conn->host.rawalloc);
|
Curl_safefree(conn->host.rawalloc);
|
||||||
conn->host=old_conn->host;
|
conn->host=old_conn->host;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
free(old_conn->host.rawalloc); /* free the newly allocated name buffer */
|
Curl_safefree(old_conn->host.rawalloc); /* free the newly allocated name buffer */
|
||||||
|
|
||||||
/* persist connection info in session handle */
|
/* persist connection info in session handle */
|
||||||
Curl_persistconninfo(conn);
|
Curl_persistconninfo(conn);
|
||||||
@ -4756,14 +4763,19 @@ static CURLcode create_conn(struct SessionHandle *data,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Curl_safefree(data->state.pathbuffer);
|
Curl_safefree(data->state.pathbuffer);
|
||||||
|
data->state.path = NULL;
|
||||||
|
|
||||||
data->state.pathbuffer = malloc(urllen+2);
|
data->state.pathbuffer = malloc(urllen+2);
|
||||||
if(NULL == data->state.pathbuffer)
|
if(NULL == data->state.pathbuffer)
|
||||||
return CURLE_OUT_OF_MEMORY; /* really bad error */
|
return CURLE_OUT_OF_MEMORY; /* really bad error */
|
||||||
data->state.path = data->state.pathbuffer;
|
data->state.path = data->state.pathbuffer;
|
||||||
|
|
||||||
conn->host.rawalloc = malloc(urllen+2);
|
conn->host.rawalloc = malloc(urllen+2);
|
||||||
if(NULL == conn->host.rawalloc)
|
if(NULL == conn->host.rawalloc) {
|
||||||
|
Curl_safefree(data->state.pathbuffer);
|
||||||
|
data->state.path = NULL;
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
conn->host.name = conn->host.rawalloc;
|
conn->host.name = conn->host.rawalloc;
|
||||||
conn->host.name[0] = 0;
|
conn->host.name[0] = 0;
|
||||||
@ -4788,6 +4800,11 @@ static CURLcode create_conn(struct SessionHandle *data,
|
|||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data->change.url_alloc) {
|
||||||
|
Curl_safefree(data->change.url);
|
||||||
|
data->change.url_alloc = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
data->change.url = reurl;
|
data->change.url = reurl;
|
||||||
data->change.url_alloc = TRUE; /* free this later */
|
data->change.url_alloc = TRUE; /* free this later */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user