[PATCH] util: Fix crash when removing entries during hash iteration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 is an alternate less invasive fix to "util: Simplify hash implementation".
I prefer the more invasive fix for upstream but I'm sending this alternative
here for completeness.

 src/util/hash.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/util/hash.c b/src/util/hash.c
index 48a94ad..fc7652d 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;
         }
-- 
1.7.5.rc1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]