diff --git a/server/core/hashtable.c b/server/core/hashtable.c index 50857bfec..b945f3631 100644 --- a/server/core/hashtable.c +++ b/server/core/hashtable.c @@ -79,9 +79,13 @@ nullfn(void *data) } /** - * Allocate a new hash table + * Allocate a new hash table. * - * @param size The size of the hash table + * The hashtable must have a size of at least one, however to be of any + * practical use a larger size sould be chosen as the size relates to the number + * of has buckets in the table. + * + * @param size The size of the hash table, msut be > 0 * @param hashfn The user supplied hash function * @param cmpfn The user supplied key comparison function * @return The hashtable table @@ -218,6 +222,7 @@ hashtable_add(HASHTABLE *table, void *key, void *value) /* check succesfull key copy */ if ( ptr->key == NULL) { + hashtable_write_unlock(table); return 0; } @@ -230,6 +235,7 @@ hashtable_add(HASHTABLE *table, void *key, void *value) table->kfreefn(ptr->key); /* value not copied, return */ + hashtable_write_unlock(table); return 0; } @@ -546,10 +552,10 @@ HASHENTRIES *entries; iter->depth++; while (iter->chain < iter->table->hashsize) { + hashtable_read_lock(iter->table); if ((entries = iter->table->entries[iter->chain]) != NULL) { i = 0; - hashtable_read_lock(iter->table); while (entries && i < iter->depth) { entries = entries->next; @@ -559,6 +565,10 @@ HASHENTRIES *entries; if (entries) return entries->key; } + else + { + hashtable_read_unlock(iter->table); + } iter->depth = 0; iter->chain++; }