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

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@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

We need to free the string returned by gvir_config_object_to_xml() after using it. Signed-off-by: Christophe Fergeau <cfergeau@redhat.com> --- 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 c48d51b9..15b47093 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1999,7 +1999,7 @@ GVirStoragePool *gvir_connection_create_storage_pool GVirConfigStoragePool *conf, guint flags, GError **err) { - const gchar *xml; + gchar *xml; virStoragePoolPtr handle; GVirConnectionPrivate *priv; @@ -2012,7 +2012,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.20.1

On Tue, Feb 12, 2019 at 9:08 AM Christophe Fergeau <cfergeau@redhat.com> wrote:
We need to free the string returned by gvir_config_object_to_xml() after using it.
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>

It's not used outside of the libvirt-glib-event.c file, so there is no good reason for not having it static. As it was not listed in libvirt-glib.sym, this will make no changes to the publicly exported symbols (ie this is not an ABI change). Signed-off-by: Christophe Fergeau <cfergeau@redhat.com> --- libvirt-glib/libvirt-glib-event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvirt-glib/libvirt-glib-event.c b/libvirt-glib/libvirt-glib-event.c index f8227d61..4548aa65 100644 --- a/libvirt-glib/libvirt-glib-event.c +++ b/libvirt-glib/libvirt-glib-event.c @@ -110,7 +110,7 @@ struct gvir_event_timeout virFreeCallback ff; }; -GMutex *eventlock = NULL; +static GMutex *eventlock = NULL; static int nextwatch = 1; static GPtrArray *handles; -- 2.20.1

On Tue, Feb 12, 2019 at 9:07 AM Christophe Fergeau <cfergeau@redhat.com> wrote:
It's not used outside of the libvirt-glib-event.c file, so there is no good reason for not having it static. As it was not listed in libvirt-glib.sym, this will make no changes to the publicly exported symbols (ie this is not an ABI change).
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>

On Tue, Feb 12, 2019 at 9:07 AM Christophe Fergeau <cfergeau@redhat.com> wrote:
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@redhat.com>
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
participants (2)
-
Christophe Fergeau
-
Fabiano Fidêncio