diff options
author | Yang Tse <yangsita@gmail.com> | 2011-10-11 19:41:30 +0200 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2011-10-11 19:41:30 +0200 |
commit | 584dc8b8af862f7f47a3a9f02f874ac0bd0076be (patch) | |
tree | 5e5ff41b3862251704b8f46f36bcf9052ad48e52 | |
parent | a84b8a39224d0c668d80fed561bc89b4144edbb4 (diff) |
OOM handling/cleanup slight adjustments
-rw-r--r-- | lib/cookie.c | 2 | ||||
-rw-r--r-- | lib/fileinfo.c | 3 | ||||
-rw-r--r-- | lib/hash.c | 17 | ||||
-rw-r--r-- | lib/llist.c | 2 | ||||
-rw-r--r-- | lib/multi.c | 14 | ||||
-rw-r--r-- | lib/ssluse.c | 3 | ||||
-rw-r--r-- | lib/url.c | 18 |
7 files changed, 38 insertions, 21 deletions
diff --git a/lib/cookie.c b/lib/cookie.c index fc684ca1b..41ccdbe34 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 16166687e..4ffcbbe29 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 15b3efff6..3704eea41 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 0aecf1083..a302e32d5 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 7786ccced..8a8779c23 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 51bd909a1..d65fd98b9 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; } @@ -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; |