Added checks for possible handle hashtable_add() failure
Added checks for possible handle hashtable_add() failure with key, value and copyfn
This commit is contained in:
parent
b673108276
commit
5fd5aab2be
@ -184,6 +184,9 @@ hashtable_add(HASHTABLE *table, void *key, void *value)
|
||||
int hashkey;
|
||||
HASHENTRIES *entry;
|
||||
|
||||
if (key == NULL || value == NULL)
|
||||
return 0;
|
||||
|
||||
if (table->hashsize <= 0) {
|
||||
return 0;
|
||||
} else {
|
||||
@ -209,8 +212,27 @@ hashtable_add(HASHTABLE *table, void *key, void *value)
|
||||
hashtable_write_unlock(table);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* copy the key */
|
||||
ptr->key = table->kcopyfn(key);
|
||||
|
||||
/* check succesfull key copy */
|
||||
if ( ptr->key == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* copy the value */
|
||||
ptr->value = table->vcopyfn(value);
|
||||
|
||||
/* check succesfull value copy */
|
||||
if ( ptr->value == NULL) {
|
||||
/* remove the key ! */
|
||||
table->kfreefn(ptr->key);
|
||||
|
||||
/* value not copied, return */
|
||||
return 0;
|
||||
}
|
||||
|
||||
ptr->next = table->entries[hashkey % table->hashsize];
|
||||
table->entries[hashkey % table->hashsize] = ptr;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user