[libvirt-glib] Fix [gs]et_custom_xml-related leaks

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

 



I forgot to run the testing code through valgrind before pushing
the patches so a few small memory leaks crept in.
---
 libvirt-gconfig/libvirt-gconfig-domain.c   |    1 +
 libvirt-gconfig/tests/test-domain-create.c |    8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index d7ac4c6..177c926 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -479,6 +479,7 @@ gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain,
     gvir_config_object_delete_children(metadata, NULL, ns_uri);
     gvir_config_object_attach_add(metadata, custom_xml);
     g_object_unref(G_OBJECT(metadata));
+    g_object_unref(G_OBJECT(custom_xml));
 
     return TRUE;
 }
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
index 1610587..821e0b0 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -177,8 +177,12 @@ int main(int argc, char **argv)
     gvir_config_domain_set_custom_xml(domain, "<foo/>", "ns", "http://bar";, NULL);
     gvir_config_domain_set_custom_xml(domain, "<bar/>", "ns", "http://foo";, NULL);
 
-    g_assert(g_strcmp0(gvir_config_domain_get_custom_xml(domain, "http://foo";), "<ns:bar xmlns:ns=\"http://foo\"/>") == 0);
-    g_assert(g_strcmp0(gvir_config_domain_get_custom_xml(domain, "http://bar";), "<ns:foo xmlns:ns=\"http://bar\"/>") == 0);
+    xml = gvir_config_domain_get_custom_xml(domain, "http://foo";);
+    g_assert(g_strcmp0(xml, "<ns:bar xmlns:ns=\"http://foo\"/>") == 0);
+    g_free(xml);
+    xml = gvir_config_domain_get_custom_xml(domain, "http://bar";);
+    g_assert(g_strcmp0(xml, "<ns:foo xmlns:ns=\"http://bar\"/>") == 0);
+    g_free(xml);
 
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain));
     g_print("%s\n\n", xml);
-- 
1.7.7.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


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