mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
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.
This commit is contained in:
parent
50e4b9195d
commit
5c53160a2f
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user