}
}
+ VIR_FREE(table->table);
VIR_FREE(table);
}
* virHashRemoveSet
* @table: the hash table to process
* @iter: callback to identify elements for removal
- * @f: callback to free memory from element payload
* @data: opaque data to pass to the iterator
*
* Iterates over all elements in the hash table, invoking the 'iter'
* callback. If the callback returns a non-zero value, the element
* will be removed from the hash table & its payload passed to the
- * callback 'f' for de-allocation.
+ * data freer callback registered at creation.
*
* Returns number of items removed on success, -1 on failure
*/
while (*nextptr) {
virHashEntryPtr entry = *nextptr;
if (!iter(entry->payload, entry->name, data)) {
- *nextptr = entry->next;
+ nextptr = &entry->next;
} else {
count++;
if (table->dataFree)
return hash;
}
+static void
+testHashCheckForEachCount(void *payload ATTRIBUTE_UNUSED,
+ const void *name ATTRIBUTE_UNUSED,
+ void *data ATTRIBUTE_UNUSED)
+{
+}
static int
testHashCheckCount(virHashTablePtr hash, int count)
{
+ int iter_count = 0;
+
if (virHashSize(hash) != count) {
testError("\nhash contains %d instead of %d elements\n",
virHashSize(hash), count);
return -1;
}
+ iter_count = virHashForEach(hash, testHashCheckForEachCount, NULL);
+ if (count != iter_count) {
+ testError("\nhash claims to have %d elements but iteration finds %d\n",
+ count, iter_count);
+ return -1;
+ }
+
return 0;
}