Fix bugs 484 and 485.
This commit is contained in:
@ -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 hashfn The user supplied hash function
|
||||||
* @param cmpfn The user supplied key comparison function
|
* @param cmpfn The user supplied key comparison function
|
||||||
* @return The hashtable table
|
* @return The hashtable table
|
||||||
@ -218,6 +222,7 @@ hashtable_add(HASHTABLE *table, void *key, void *value)
|
|||||||
|
|
||||||
/* check succesfull key copy */
|
/* check succesfull key copy */
|
||||||
if ( ptr->key == NULL) {
|
if ( ptr->key == NULL) {
|
||||||
|
hashtable_write_unlock(table);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,6 +235,7 @@ hashtable_add(HASHTABLE *table, void *key, void *value)
|
|||||||
table->kfreefn(ptr->key);
|
table->kfreefn(ptr->key);
|
||||||
|
|
||||||
/* value not copied, return */
|
/* value not copied, return */
|
||||||
|
hashtable_write_unlock(table);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,10 +552,10 @@ HASHENTRIES *entries;
|
|||||||
iter->depth++;
|
iter->depth++;
|
||||||
while (iter->chain < iter->table->hashsize)
|
while (iter->chain < iter->table->hashsize)
|
||||||
{
|
{
|
||||||
|
hashtable_read_lock(iter->table);
|
||||||
if ((entries = iter->table->entries[iter->chain]) != NULL)
|
if ((entries = iter->table->entries[iter->chain]) != NULL)
|
||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
hashtable_read_lock(iter->table);
|
|
||||||
while (entries && i < iter->depth)
|
while (entries && i < iter->depth)
|
||||||
{
|
{
|
||||||
entries = entries->next;
|
entries = entries->next;
|
||||||
@ -559,6 +565,10 @@ HASHENTRIES *entries;
|
|||||||
if (entries)
|
if (entries)
|
||||||
return entries->key;
|
return entries->key;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hashtable_read_unlock(iter->table);
|
||||||
|
}
|
||||||
iter->depth = 0;
|
iter->depth = 0;
|
||||||
iter->chain++;
|
iter->chain++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user