summaryrefslogtreecommitdiff
path: root/lib/hash.c
diff options
context:
space:
mode:
authorAnthony Avina <aavina2@gmail.com>2015-05-02 13:49:55 -0500
committerDaniel Stenberg <daniel@haxx.se>2015-05-18 11:15:43 +0200
commit4883f7019d3f8a50b2f94e8e6c2e6123840e5a14 (patch)
tree89255e69e5d052255d215a8da7718113a723944b /lib/hash.c
parent39b9bf60d13ff7cb62a6a031c210d27a32113c4f (diff)
downloadcurl-4883f7019d3f8a50b2f94e8e6c2e6123840e5a14.tar.gz
hostip: fix unintended destruction of hash table
.. and added unit1602 for hash.c
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c18
1 files changed, 16 insertions, 2 deletions
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 */
}