From 5b75b1988bc5970cb1bb5b6c4bd07e772c159ba0 Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Wed, 16 Nov 2011 12:19:47 +0100 Subject: Imported Upstream version 7.23.0 --- lib/hash.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'lib/hash.c') diff --git a/lib/hash.c b/lib/hash.c index 3a6e312a..3704eea4 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); } @@ -72,16 +75,22 @@ Curl_hash_init(struct curl_hash *h, for(i = 0; i < slots; ++i) { h->table[i] = Curl_llist_alloc((curl_llist_dtor) hash_element_dtor); if(!h->table[i]) { - while(i--) + while(i--) { Curl_llist_destroy(h->table[i], NULL); + h->table[i] = NULL; + } 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 * @@ -187,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; } } @@ -240,6 +250,9 @@ Curl_hash_clean(struct curl_hash *h) } free(h->table); + h->table = NULL; + h->size = 0; + h->slots = 0; } void -- cgit v1.2.3