Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8151:10a5483c0d02 HEAD
hash2_remove_iter(): Never resize hash table, otherwise iteration breaks.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 01 Sep 2008 17:41:12 +0300 |
parents | 7b5120f7f732 |
children | 9690f8a1d21f |
files | src/lib/hash2.c |
diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/hash2.c Mon Sep 01 17:07:37 2008 +0300 +++ b/src/lib/hash2.c Mon Sep 01 17:41:12 2008 +0300 @@ -183,8 +183,9 @@ return value + 1; } -static void hash2_remove_value_p(struct hash2_table *hash, - struct hash2_value **valuep) +static void +hash2_remove_value_p(struct hash2_table *hash, struct hash2_value **valuep, + bool allow_resize) { struct hash2_value *deleted_value; @@ -195,7 +196,8 @@ hash->deleted_values = deleted_value; hash->count--; - hash2_resize(hash, FALSE); + if (allow_resize) + hash2_resize(hash, FALSE); } void hash2_remove(struct hash2_table *hash, const void *key) @@ -208,7 +210,7 @@ while (*valuep != NULL) { if ((*valuep)->key_hash == key_hash && hash->key_compare_cb(key, (*valuep) + 1, hash->context)) { - hash2_remove_value_p(hash, valuep); + hash2_remove_value_p(hash, valuep, TRUE); return; } valuep = &(*valuep)->next; @@ -225,7 +227,9 @@ while (*valuep != NULL) { if (*valuep == iter->value) { next = (*valuep)->next; - hash2_remove_value_p(hash, valuep); + /* don't allow resizing, otherwise iterating would + break completely */ + hash2_remove_value_p(hash, valuep, FALSE); iter->next_value = next; return; }