From 81dd3f141822023be2ce419c082dcf68d0ab973d Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 27 Feb 2024 20:21:06 +0100 Subject: [PATCH] fixed function to iterate through hash table and remove hash entries --- src/libgame/hash.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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); -- 2.34.1