From: Yang Tse Date: Tue, 11 Oct 2011 17:41:30 +0000 (+0200) Subject: OOM handling/cleanup slight adjustments X-Git-Tag: upstream/7.37.1~3598 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=584dc8b8af862f7f47a3a9f02f874ac0bd0076be;p=platform%2Fupstream%2Fcurl.git OOM handling/cleanup slight adjustments --- diff --git a/lib/cookie.c b/lib/cookie.c index fc684ca..41ccdbe 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -144,9 +144,9 @@ void Curl_cookie_loadfiles(struct SessionHandle *data) data->set.cookiesession); list = list->next; } - Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); curl_slist_free_all(data->change.cookielist); /* clean up list */ data->change.cookielist = NULL; /* don't do this again! */ + Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); } } diff --git a/lib/fileinfo.c b/lib/fileinfo.c index 1616668..4ffcbbe 100644 --- a/lib/fileinfo.c +++ b/lib/fileinfo.c @@ -48,8 +48,7 @@ void Curl_fileinfo_dtor(void *user, void *element) if(!finfo) return; - if(finfo->b_data) - free(finfo->b_data); + Curl_safefree(finfo->b_data); free(finfo); } diff --git a/lib/hash.c b/lib/hash.c index 15b3eff..3704eea 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -38,11 +38,14 @@ hash_element_dtor(void *user, void *element) struct curl_hash *h = (struct curl_hash *) user; struct curl_hash_element *e = (struct curl_hash_element *) element; - if(e->key) - free(e->key); + Curl_safefree(e->key); - if(e->ptr) + if(e->ptr) { h->dtor(e->ptr); + e->ptr = NULL; + } + + e->key_len = 0; free(e); } @@ -78,13 +81,16 @@ Curl_hash_init(struct curl_hash *h, } free(h->table); h->table = NULL; + h->slots = 0; return 1; /* failure */ } } return 0; /* fine */ } - else + else { + h->slots = 0; return 1; /* failure */ + } } struct curl_hash * @@ -190,6 +196,7 @@ int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len) he = le->ptr; if(h->comp_func(he->key, he->key_len, key, key_len)) { Curl_llist_remove(l, le, (void *) h); + --h->size; return 0; } } @@ -244,6 +251,8 @@ Curl_hash_clean(struct curl_hash *h) free(h->table); h->table = NULL; + h->size = 0; + h->slots = 0; } void diff --git a/lib/llist.c b/lib/llist.c index 0aecf10..a302e32 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -46,7 +46,7 @@ Curl_llist_alloc(curl_llist_dtor dtor) struct curl_llist *list; list = malloc(sizeof(struct curl_llist)); - if(NULL == list) + if(!list) return NULL; llist_init(list, dtor); diff --git a/lib/multi.c b/lib/multi.c index 7786ccc..8a8779c 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -425,12 +425,13 @@ CURLM *curl_multi_init(void) return (CURLM *) multi; error: - if(multi->sockhash) - Curl_hash_destroy(multi->sockhash); - if(multi->hostcache) - Curl_hash_destroy(multi->hostcache); - if(multi->connc) - Curl_rm_connc(multi->connc); + + Curl_hash_destroy(multi->sockhash); + multi->sockhash = NULL; + Curl_hash_destroy(multi->hostcache); + multi->hostcache = NULL; + Curl_rm_connc(multi->connc); + multi->connc = NULL; free(multi); return NULL; @@ -1801,6 +1802,7 @@ CURLMcode curl_multi_cleanup(CURLM *multi_handle) } Curl_rm_connc(multi->connc); + multi->connc = NULL; /* remove the pending list of messages */ Curl_llist_destroy(multi->msglist, NULL); diff --git a/lib/ssluse.c b/lib/ssluse.c index 51bd909..d65fd98 100644 --- a/lib/ssluse.c +++ b/lib/ssluse.c @@ -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 like in this place the extra malloc/free is totally pointless */ nl = curl_slist_append(ci->certinfo[certnum], output); + free(output); if(!nl) { curl_slist_free_all(ci->certinfo[certnum]); ci->certinfo[certnum] = NULL; @@ -1863,8 +1864,6 @@ static CURLcode push_certinfo_len(struct SessionHandle *data, else ci->certinfo[certnum] = nl; - free(output); - return res; } diff --git a/lib/url.c b/lib/url.c index 7813b82..7eb59f5 100644 --- a/lib/url.c +++ b/lib/url.c @@ -458,6 +458,7 @@ CURLcode Curl_close(struct SessionHandle *data) /* free the connection cache if allocated privately */ Curl_rm_connc(data->state.connc); + data->state.connc = NULL; } } @@ -618,13 +619,19 @@ CURLcode Curl_ch_connc(struct SessionHandle *data, curl_multi_cleanup(). */ void Curl_rm_connc(struct conncache *c) { + if(!c) + return; + if(c->connects) { long i; - for(i = 0; i < c->num; ++i) + for(i = 0; i < c->num; ++i) { conn_free(c->connects[i]); - + c->connects[i] = NULL; + } free(c->connects); + c->connects = NULL; } + c->num = 0; 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 them later */ 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; - + } data->change.cookielist = cl; /* store the list for later use */ } break;