From: Jiri Denemark Date: Tue, 12 Apr 2011 15:58:22 +0000 (+0200) Subject: util: Fix crash when removing entries during hash iteration X-Git-Tag: v0.9.1~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c53160a2f7c64ce94a3bc1e964ab71ffb2e2c23;p=thirdparty%2Flibvirt.git util: Fix crash when removing entries during hash iteration Commit 9677cd33eea4c65d78ba463b46b8b45ed2da1709 made it possible to remove current entry when iterating through all hash entries. However, it didn't properly handle a special case of removing first entry assigned to a given key which contains several entries in its collision list. --- diff --git a/src/util/hash.c b/src/util/hash.c index 48a94ad12d..fc7652d292 100644 --- a/src/util/hash.c +++ b/src/util/hash.c @@ -585,10 +585,18 @@ int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data) while (entry) { virHashEntryPtr next = entry->next; if (entry->valid) { + void *name = (entry == table->table + i) ? entry->name : NULL; + table->current = entry; iter(entry->payload, entry->name, data); table->current = NULL; count++; + + /* revisit current entry if it was the first one in collision + * list and its content changed, i.e. it was deleted by iter() + */ + if (name && name != entry->name) + continue; } entry = next; }