[PATCH v2 04/40] util: add function to unref array of GObjects

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

 



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@xxxxxxxxx>
---
 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 2cde3c9aa5..4286efdd36 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2734,6 +2734,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.25.3






[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]

  Powered by Linux