summaryrefslogtreecommitdiff
path: root/lib/hash.c
diff options
context:
space:
mode:
authorAlessandro Ghedini <al3xbio@gmail.com>2011-11-16 12:19:47 +0100
committerAlessandro Ghedini <al3xbio@gmail.com>2011-11-16 12:19:47 +0100
commit5b75b1988bc5970cb1bb5b6c4bd07e772c159ba0 (patch)
tree458cf7df0db762a0f9ac7e6cbf8256e40aa1e640 /lib/hash.c
parent364250c4614d2c23623d712027fa93f7d58aaf99 (diff)
Imported Upstream version 7.23.0
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c23
1 files changed, 18 insertions, 5 deletions
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