If xmlNodeDump() fails, we would be leaking the xmlBuffer we created.
This commit ensures we don't return early before this buffer is freed.
---
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 0314a72..e8f9664 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.7.4
Show replies by date
We need to free the string returned by gvir_config_object_to_xml() after
using it.
---
libvirt-gobject/libvirt-gobject-connection.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-connection.c
b/libvirt-gobject/libvirt-gobject-connection.c
index 3f17265..da3db50 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -2001,7 +2001,7 @@ GVirStoragePool *gvir_connection_create_storage_pool
GVirConfigStoragePool *conf,
guint flags,
GError **err) {
- const gchar *xml;
+ gchar *xml;
virStoragePoolPtr handle;
GVirConnectionPrivate *priv;
@@ -2014,7 +2014,9 @@ GVirStoragePool *gvir_connection_create_storage_pool
g_return_val_if_fail(xml != NULL, NULL);
priv = conn->priv;
- if (!(handle = virStoragePoolDefineXML(priv->conn, xml, flags))) {
+ handle = virStoragePoolDefineXML(priv->conn, xml, flags);
+ g_free(xml);
+ if (!handle) {
gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
flags,
_("Failed to create storage pool"));
--
2.7.4