diff options
author | Anthony Avina <aavina2@gmail.com> | 2015-05-02 13:49:55 -0500 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2015-05-18 11:15:43 +0200 |
commit | 4883f7019d3f8a50b2f94e8e6c2e6123840e5a14 (patch) | |
tree | 89255e69e5d052255d215a8da7718113a723944b /lib | |
parent | 39b9bf60d13ff7cb62a6a031c210d27a32113c4f (diff) | |
download | curl-4883f7019d3f8a50b2f94e8e6c2e6123840e5a14.tar.gz |
hostip: fix unintended destruction of hash table
.. and added unit1602 for hash.c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/conncache.c | 2 | ||||
-rw-r--r-- | lib/hash.c | 18 | ||||
-rw-r--r-- | lib/hash.h | 1 | ||||
-rw-r--r-- | lib/hostip.c | 2 | ||||
-rw-r--r-- | lib/multi.c | 8 | ||||
-rw-r--r-- | lib/share.c | 2 |
6 files changed, 24 insertions, 9 deletions
diff --git a/lib/conncache.c b/lib/conncache.c index 634b673e3..5c3957519 100644 --- a/lib/conncache.c +++ b/lib/conncache.c @@ -126,7 +126,7 @@ int Curl_conncache_init(struct conncache *connc, int size) void Curl_conncache_destroy(struct conncache *connc) { if(connc) - Curl_hash_clean(&connc->hash); + Curl_hash_destroy(&connc->hash); } /* returns an allocated key to find a bundle for this connection */ diff --git a/lib/hash.c b/lib/hash.c index b1aebd5b8..c46760ae1 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -212,8 +212,11 @@ Curl_hash_apply(curl_hash *h, void *user, } #endif +/* Destroys all the entries in the given hash and resets its attributes, + * prepping the given hash for [static|dynamic] deallocation. + */ void -Curl_hash_clean(struct curl_hash *h) +Curl_hash_destroy(struct curl_hash *h) { int i; @@ -227,6 +230,17 @@ Curl_hash_clean(struct curl_hash *h) h->slots = 0; } +/* Removes all the entries in the given hash. + * + * @unittest: 1602 + */ +void +Curl_hash_clean(struct curl_hash *h) +{ + Curl_hash_clean_with_criterium(h, NULL, NULL); +} + +/* Cleans all entries that pass the comp function criteria. */ void Curl_hash_clean_with_criterium(struct curl_hash *h, void *user, int (*comp)(void *, void *)) @@ -246,7 +260,7 @@ Curl_hash_clean_with_criterium(struct curl_hash *h, void *user, struct curl_hash_element *he = le->ptr; lnext = le->next; /* ask the callback function if we shall remove this entry or not */ - if(comp(user, he->ptr)) { + if(comp == NULL || comp(user, he->ptr)) { Curl_llist_remove(list, le, (void *) h); --h->size; /* one less entry in the hash now */ } diff --git a/lib/hash.h b/lib/hash.h index bc7c20dec..b13a236bb 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -80,6 +80,7 @@ void *Curl_hash_pick(struct curl_hash *, void * key, size_t key_len); void Curl_hash_apply(struct curl_hash *h, void *user, void (*cb)(void *user, void *ptr)); int Curl_hash_count(struct curl_hash *h); +void Curl_hash_destroy(struct curl_hash *h); void Curl_hash_clean(struct curl_hash *h); void Curl_hash_clean_with_criterium(struct curl_hash *h, void *user, int (*comp)(void *, void *)); diff --git a/lib/hostip.c b/lib/hostip.c index 338cf2de6..82f3897f9 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -137,7 +137,7 @@ struct curl_hash *Curl_global_host_cache_init(void) void Curl_global_host_cache_dtor(void) { if(host_cache_initialized) { - Curl_hash_clean(&hostname_cache); + Curl_hash_destroy(&hostname_cache); host_cache_initialized = 0; } } diff --git a/lib/multi.c b/lib/multi.c index 718f65816..2a7d8bede 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -324,8 +324,8 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */ error: - Curl_hash_clean(&multi->sockhash); - Curl_hash_clean(&multi->hostcache); + Curl_hash_destroy(&multi->sockhash); + Curl_hash_destroy(&multi->hostcache); Curl_conncache_destroy(&multi->conn_cache); Curl_close(multi->closure_handle); multi->closure_handle = NULL; @@ -1874,7 +1874,7 @@ CURLMcode curl_multi_cleanup(CURLM *multi_handle) Curl_close(multi->closure_handle); } - Curl_hash_clean(&multi->sockhash); + Curl_hash_destroy(&multi->sockhash); Curl_conncache_destroy(&multi->conn_cache); Curl_llist_destroy(multi->msglist, NULL); Curl_llist_destroy(multi->pending, NULL); @@ -1897,7 +1897,7 @@ CURLMcode curl_multi_cleanup(CURLM *multi_handle) data = nextdata; } - Curl_hash_clean(&multi->hostcache); + Curl_hash_destroy(&multi->hostcache); /* Free the blacklists by setting them to NULL */ Curl_pipeline_set_site_blacklist(NULL, &multi->pipelining_site_bl); diff --git a/lib/share.c b/lib/share.c index b61a86bc2..7fb068625 100644 --- a/lib/share.c +++ b/lib/share.c @@ -188,7 +188,7 @@ curl_share_cleanup(CURLSH *sh) return CURLSHE_IN_USE; } - Curl_hash_clean(&share->hostcache); + Curl_hash_destroy(&share->hostcache); #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) Curl_cookie_cleanup(share->cookies); |