[libvirt] [libvirt-glib 1/3] config: Fix gvir_config_xml_node_to_string() leak

Christophe Fergeau cfergeau at redhat.com
Tue Feb 12 08:06:05 UTC 2019


If xmlNodeDump() fails, we would be leaking the xmlBuffer we created.
This commit ensures we don't return early before this buffer is freed.

Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
---
 libvirt-gconfig/libvirt-gconfig-helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c b/libvirt-gconfig/libvirt-gconfig-helpers.c
index 0314a72f..e8f9664a 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers.c
+++ b/libvirt-gconfig/libvirt-gconfig-helpers.c
@@ -293,7 +293,7 @@ gvir_config_xml_node_to_string(xmlNodePtr node)
 
     xmlbuf = xmlBufferCreate();
     if (xmlNodeDump(xmlbuf, node->doc, node, 0, 1) < 0)
-        return NULL;
+        xml = NULL;
     else
         xml = g_strndup((gchar *)xmlBufferContent(xmlbuf), xmlBufferLength(xmlbuf));
 
-- 
2.20.1




More information about the libvir-list mailing list