As types are slowly converted to GObject, a helper function to unref all
the GObjects in an array will come in handy, as it's already the case
with virObject.
Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/libvirt_private.syms | 1 +
src/util/virobject.c | 24 ++++++++++++++++++++++++
src/util/virobject.h | 4 ++++
3 files changed, 29 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1796ef5cbe..88fdc1a3a8 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2744,6 +2744,7 @@ virClassForObjectRWLockable;
virClassIsDerivedFrom;
virClassName;
virClassNew;
+virGObjectListFreeCount;
virObjectFreeCallback;
virObjectFreeHashData;
virObjectIsClass;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index c71781550f..9030fb1625 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -29,6 +29,7 @@
#include "virlog.h"
#include "virprobe.h"
#include "virstring.h"
+#include <glib-object.h>
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -636,3 +637,26 @@ virObjectListFreeCount(void *list,
VIR_FREE(list);
}
+
+
+/**
+ * virGObjectListFreeCount:
+ * @list: A pointer to a list of GObject pointers to free
+ * @count: Number of elements in the list.
+ *
+ * Unrefs all members of @list and frees the list itself.
+ */
+void
+virGObjectListFreeCount(void *list,
+ size_t count)
+{
+ size_t i;
+
+ if (!list)
+ return;
+
+ for (i = 0; i < count; i++)
+ g_clear_object(&((GObject **)list)[i]);
+
+ VIR_FREE(list);
+}
diff --git a/src/util/virobject.h b/src/util/virobject.h
index 62a8a3d132..1af048aefc 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -159,3 +159,7 @@ virObjectListFree(void *list);
void
virObjectListFreeCount(void *list,
size_t count);
+
+void
+virGObjectListFreeCount(void *list,
+ size_t count);
--
2.26.2