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

[libvirt] [libvirt-glib 06/13] Use gvir_config_object_attach where appropriate



This allows us to properly refcount the underlying xmlDocPtr (and
the associated xmlNodes) to avoid trying to free twice the same
xmlNodes when disposing of GVirConfigObject referencing the same
nodes.
---
 libvirt-gconfig/libvirt-gconfig-domain.c |   31 ++++++++++++++---------------
 1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index 2c21219..d9cb2e9 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -266,25 +266,21 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain,
 void gvir_config_domain_set_clock(GVirConfigDomain *domain,
                                   GVirConfigDomainClock *klock)
 {
-    xmlNodePtr clock_node;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN(domain));
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CLOCK(klock));
 
-    clock_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock));
-    gvir_config_object_set_child(GVIR_CONFIG_OBJECT(domain), clock_node);
+    gvir_config_object_attach(GVIR_CONFIG_OBJECT(domain),
+                              GVIR_CONFIG_OBJECT(klock));
 }
 
 void gvir_config_domain_set_os(GVirConfigDomain *domain,
                                GVirConfigDomainOs *os)
 {
-    xmlNodePtr os_node;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN(domain));
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os));
 
-    os_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os));
-    gvir_config_object_set_child(GVIR_CONFIG_OBJECT(domain), os_node);
+    gvir_config_object_attach(GVIR_CONFIG_OBJECT(domain),
+                              GVIR_CONFIG_OBJECT(os));
 }
 
 /**
@@ -294,18 +290,21 @@ void gvir_config_domain_set_os(GVirConfigDomain *domain,
 void gvir_config_domain_set_devices(GVirConfigDomain *domain,
                                     GList *devices)
 {
-    xmlNodePtr devices_node;
+    GVirConfigObject *devices_node;
     GList *it;
 
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN(domain));
 
-    devices_node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(domain),
-                                                    "devices");
+    devices_node = gvir_config_object_new(GVIR_TYPE_CONFIG_OBJECT,
+                                          "devices", NULL);
     for (it = devices; it != NULL; it = it->next) {
-        GVirConfigDomainDevice *device = GVIR_CONFIG_DOMAIN_DEVICE(it->data);
-        xmlNodePtr node;
-
-        node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(device));
-        xmlAddChild(devices_node, node);
+        if (!GVIR_IS_CONFIG_DOMAIN_DEVICE(it->data)) {
+            g_warn_if_reached();
+            continue;
+        }
+        gvir_config_object_attach(devices_node, GVIR_CONFIG_OBJECT(it->data));
     }
+
+    gvir_config_object_attach(GVIR_CONFIG_OBJECT(domain), devices_node);
+    g_object_unref(G_OBJECT(devices_node));
 }
-- 
1.7.7.3


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