1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 16:18:48 -05:00

OOM handling/cleanup slight adjustments

This commit is contained in:
Yang Tse 2011-10-11 19:41:30 +02:00
parent a84b8a3922
commit 584dc8b8af
7 changed files with 38 additions and 21 deletions

View File

@ -144,9 +144,9 @@ void Curl_cookie_loadfiles(struct SessionHandle *data)
data->set.cookiesession); data->set.cookiesession);
list = list->next; list = list->next;
} }
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
curl_slist_free_all(data->change.cookielist); /* clean up list */ curl_slist_free_all(data->change.cookielist); /* clean up list */
data->change.cookielist = NULL; /* don't do this again! */ data->change.cookielist = NULL; /* don't do this again! */
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
} }
} }

View File

@ -48,8 +48,7 @@ void Curl_fileinfo_dtor(void *user, void *element)
if(!finfo) if(!finfo)
return; return;
if(finfo->b_data) Curl_safefree(finfo->b_data);
free(finfo->b_data);
free(finfo); free(finfo);
} }

View File

@ -38,11 +38,14 @@ hash_element_dtor(void *user, void *element)
struct curl_hash *h = (struct curl_hash *) user; struct curl_hash *h = (struct curl_hash *) user;
struct curl_hash_element *e = (struct curl_hash_element *) element; struct curl_hash_element *e = (struct curl_hash_element *) element;
if(e->key) Curl_safefree(e->key);
free(e->key);
if(e->ptr) if(e->ptr) {
h->dtor(e->ptr); h->dtor(e->ptr);
e->ptr = NULL;
}
e->key_len = 0;
free(e); free(e);
} }
@ -78,13 +81,16 @@ Curl_hash_init(struct curl_hash *h,
} }
free(h->table); free(h->table);
h->table = NULL; h->table = NULL;
h->slots = 0;
return 1; /* failure */ return 1; /* failure */
} }
} }
return 0; /* fine */ return 0; /* fine */
} }
else else {
h->slots = 0;
return 1; /* failure */ return 1; /* failure */
}
} }
struct curl_hash * struct curl_hash *
@ -190,6 +196,7 @@ int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len)
he = le->ptr; he = le->ptr;
if(h->comp_func(he->key, he->key_len, key, key_len)) { if(h->comp_func(he->key, he->key_len, key, key_len)) {
Curl_llist_remove(l, le, (void *) h); Curl_llist_remove(l, le, (void *) h);
--h->size;
return 0; return 0;
} }
} }
@ -244,6 +251,8 @@ Curl_hash_clean(struct curl_hash *h)
free(h->table); free(h->table);
h->table = NULL; h->table = NULL;
h->size = 0;
h->slots = 0;
} }
void void

View File

@ -46,7 +46,7 @@ Curl_llist_alloc(curl_llist_dtor dtor)
struct curl_llist *list; struct curl_llist *list;
list = malloc(sizeof(struct curl_llist)); list = malloc(sizeof(struct curl_llist));
if(NULL == list) if(!list)
return NULL; return NULL;
llist_init(list, dtor); llist_init(list, dtor);

View File

@ -425,12 +425,13 @@ CURLM *curl_multi_init(void)
return (CURLM *) multi; return (CURLM *) multi;
error: error:
if(multi->sockhash)
Curl_hash_destroy(multi->sockhash); Curl_hash_destroy(multi->sockhash);
if(multi->hostcache) multi->sockhash = NULL;
Curl_hash_destroy(multi->hostcache); Curl_hash_destroy(multi->hostcache);
if(multi->connc) multi->hostcache = NULL;
Curl_rm_connc(multi->connc); Curl_rm_connc(multi->connc);
multi->connc = NULL;
free(multi); free(multi);
return NULL; return NULL;
@ -1801,6 +1802,7 @@ CURLMcode curl_multi_cleanup(CURLM *multi_handle)
} }
Curl_rm_connc(multi->connc); Curl_rm_connc(multi->connc);
multi->connc = NULL;
/* remove the pending list of messages */ /* remove the pending list of messages */
Curl_llist_destroy(multi->msglist, NULL); Curl_llist_destroy(multi->msglist, NULL);

View File

@ -1855,6 +1855,7 @@ static CURLcode push_certinfo_len(struct SessionHandle *data,
equivalent of curl_slist_append but doesn't strdup() the given data as equivalent of curl_slist_append but doesn't strdup() the given data as
like in this place the extra malloc/free is totally pointless */ like in this place the extra malloc/free is totally pointless */
nl = curl_slist_append(ci->certinfo[certnum], output); nl = curl_slist_append(ci->certinfo[certnum], output);
free(output);
if(!nl) { if(!nl) {
curl_slist_free_all(ci->certinfo[certnum]); curl_slist_free_all(ci->certinfo[certnum]);
ci->certinfo[certnum] = NULL; ci->certinfo[certnum] = NULL;
@ -1863,8 +1864,6 @@ static CURLcode push_certinfo_len(struct SessionHandle *data,
else else
ci->certinfo[certnum] = nl; ci->certinfo[certnum] = nl;
free(output);
return res; return res;
} }

View File

@ -458,6 +458,7 @@ CURLcode Curl_close(struct SessionHandle *data)
/* free the connection cache if allocated privately */ /* free the connection cache if allocated privately */
Curl_rm_connc(data->state.connc); Curl_rm_connc(data->state.connc);
data->state.connc = NULL;
} }
} }
@ -618,13 +619,19 @@ CURLcode Curl_ch_connc(struct SessionHandle *data,
curl_multi_cleanup(). */ curl_multi_cleanup(). */
void Curl_rm_connc(struct conncache *c) void Curl_rm_connc(struct conncache *c)
{ {
if(!c)
return;
if(c->connects) { if(c->connects) {
long i; long i;
for(i = 0; i < c->num; ++i) for(i = 0; i < c->num; ++i) {
conn_free(c->connects[i]); conn_free(c->connects[i]);
c->connects[i] = NULL;
}
free(c->connects); free(c->connects);
c->connects = NULL;
} }
c->num = 0;
free(c); free(c);
} }
@ -1258,10 +1265,11 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
/* append the cookie file name to the list of file names, and deal with /* append the cookie file name to the list of file names, and deal with
them later */ them later */
cl = curl_slist_append(data->change.cookielist, argptr); cl = curl_slist_append(data->change.cookielist, argptr);
if(!cl) {
if(!cl) curl_slist_free_all(data->change.cookielist);
data->change.cookielist = NULL;
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
}
data->change.cookielist = cl; /* store the list for later use */ data->change.cookielist = cl; /* store the list for later use */
} }
break; break;