From: Holger Schemel Date: Tue, 27 Feb 2024 19:21:06 +0000 (+0100) Subject: fixed function to iterate through hash table and remove hash entries X-Git-Tag: 4.4.0.0-test-1~278 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=81dd3f141822023be2ce419c082dcf68d0ab973d;p=rocksndiamonds.git fixed function to iterate through hash table and remove hash entries --- diff --git a/src/libgame/hash.c b/src/libgame/hash.c index 2b856f68..4dd904c9 100644 --- a/src/libgame/hash.c +++ b/src/libgame/hash.c @@ -529,17 +529,21 @@ hashtable_foreach_remove(struct hashtable *h, hashtable_remove_fn fn, void *user free(itr); - struct hashtable_itr *itr_remove = hashtable_iterator(remove); unsigned int num_removed = 0; - do + if (hashtable_count(remove) > 0) { - hashtable_remove(h, hashtable_iterator_key(itr_remove)); - num_removed++; - } - while (hashtable_iterator_advance(itr_remove)); + struct hashtable_itr *itr_remove = hashtable_iterator(remove); - free(itr_remove); + do + { + hashtable_remove(h, hashtable_iterator_key(itr_remove)); + num_removed++; + } + while (hashtable_iterator_advance(itr_remove)); + + free(itr_remove); + } hashtable_destroy(remove);