mirror of
https://github.com/curl/curl.git
synced 2026-08-26 11:13:36 +03:00
hostip: fix unintended destruction of hash table
.. and added unit1602 for hash.c
This commit is contained in:
parent
39b9bf60d1
commit
4883f7019d
11 changed files with 136 additions and 12 deletions
18
lib/hash.c
18
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 */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue