diff options
author | Alessandro Ghedini <al3xbio@gmail.com> | 2011-11-16 12:19:47 +0100 |
---|---|---|
committer | Alessandro Ghedini <al3xbio@gmail.com> | 2011-11-16 12:19:47 +0100 |
commit | 5b75b1988bc5970cb1bb5b6c4bd07e772c159ba0 (patch) | |
tree | 458cf7df0db762a0f9ac7e6cbf8256e40aa1e640 /lib/hash.c | |
parent | 364250c4614d2c23623d712027fa93f7d58aaf99 (diff) |
Imported Upstream version 7.23.0
Diffstat (limited to 'lib/hash.c')
-rw-r--r-- | lib/hash.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -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 |