From 856a057fc0a0807e9c0dd2b11c04e1f1312bdb12 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sun, 29 Apr 2007 00:20:38 +0000 Subject: Fix tons of bugs and performance issues to better list the certificates. --- ckcapi-util.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'ckcapi-util.c') diff --git a/ckcapi-util.c b/ckcapi-util.c index 3c587ac..7fd1d1d 100644 --- a/ckcapi-util.c +++ b/ckcapi-util.c @@ -202,7 +202,7 @@ typedef struct _HashEntry unsigned int hash; const void* key; size_t klen; - const void* val; + void* val; } HashEntry; @@ -252,17 +252,19 @@ ckcapi_hash_new() } void -ckcapi_hash_free(CkCapiHash* ht) +ckcapi_hash_free(CkCapiHash* ht, CkCapiHashDestroy destroy_func) { HashEntry* he; HashEntry* next; size_t i; - for(i = 0; i < ht->max; ++i) + for(i = 0; i <= ht->max; ++i) { for(he = ht->array[i]; he; ) { next = he->next; + if(destroy_func) + (destroy_func)((void*)he->val); free(he); he = next; } @@ -290,13 +292,13 @@ expand_array(CkCapiHash* ht) if(!new_array) return 0; - for(i = 0; i < ht->max; ++i) + for(i = 0; i <= ht->max; ++i) { for(he = ht->array[i]; he; he = he->next) { - unsigned int i = he->hash & new_max; - he->next = new_array[i]; - new_array[i] = he; + unsigned int j = he->hash & new_max; + he->next = new_array[j]; + new_array[j] = he; } } @@ -318,7 +320,7 @@ expand_array(CkCapiHash* ht) */ static HashEntry** -find_entry(CkCapiHash* ht, const void* key, size_t klen, const void* val) +find_entry(CkCapiHash* ht, const void* key, size_t klen, void* val) { HashEntry** hep; HashEntry* he; -- cgit v1.2.3