[virt-tools-list] [PATCH 24/47] Fix reference count handling in device list
Daniel P. Berrange
berrange at redhat.com
Wed Aug 25 19:37:19 UTC 2010
When adding an OsinfoEntity to an OsinfoList, an explicit
reference should be taken on the entity, rather than
relying on the caller to have done it.
* osinfo/osinfo_list.c: Take an extra reference when
adding an entity to the list
* osinfo/osinfo_dataread.c: Release a reference
after adding an entity to the list
---
osinfo/osinfo_dataread.c | 3 +++
osinfo/osinfo_list.c | 3 ++-
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/osinfo/osinfo_dataread.c b/osinfo/osinfo_dataread.c
index 166c82b..b212852 100644
--- a/osinfo/osinfo_dataread.c
+++ b/osinfo/osinfo_dataread.c
@@ -525,6 +525,7 @@ static int __osinfoProcessOs(OsinfoDb *db,
finished:
osinfo_list_add(OSINFO_LIST(oses), OSINFO_ENTITY(os));
+ g_object_unref(os);
return 0;
/* At end, cursor is at end of os node */
@@ -633,6 +634,7 @@ static int __osinfoProcessHypervisor(OsinfoDb *db,
finished:
osinfo_list_add(OSINFO_LIST(hypervisors), OSINFO_ENTITY(hv));
+ g_object_unref(hv);
return 0;
/* At end, cursor is at end of hv node */
@@ -725,6 +727,7 @@ static int __osinfoProcessDevice(OsinfoDb *db,
finished:
// Add dev to db
osinfo_list_add(OSINFO_LIST(devices), OSINFO_ENTITY(dev));
+ g_object_unref(dev);
return 0;
/* At end, cursor is at end of device node */
diff --git a/osinfo/osinfo_list.c b/osinfo/osinfo_list.c
index 7e2d833..b5eed93 100644
--- a/osinfo/osinfo_list.c
+++ b/osinfo/osinfo_list.c
@@ -38,7 +38,7 @@ osinfo_list_init (OsinfoList *self)
OsinfoListPrivate *priv;
self->priv = priv = OSINFO_LIST_GET_PRIVATE(self);
- self->priv->array = g_ptr_array_new();
+ self->priv->array = g_ptr_array_new_with_free_func(g_object_unref);
}
gint osinfo_list_get_length(OsinfoList *self)
@@ -66,6 +66,7 @@ OsinfoEntity *osinfo_list_find_by_id(OsinfoList *self, const gchar *id)
void osinfo_list_add(OsinfoList *self, OsinfoEntity *entity)
{
+ g_object_ref(entity);
g_ptr_array_add(self->priv->array, entity);
}
--
1.7.2.1
More information about the virt-tools-list
mailing list