[libvirt] [PATCH libvirt-glib 3/5] Ensure internal copy of URI is not NULL

Christophe Fergeau cfergeau at redhat.com
Wed Nov 30 17:33:23 UTC 2011


On Wed, Nov 30, 2011 at 04:52:05PM +0000, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at redhat.com>
> 
> It is permissible to pass in NULL for a URI to libvirt, which
> causes it to probe for a supported driver. In such a case we
> should populate priv->uri with the resulting probed URI after
> opening the connection
> 
> * libvirt-gobject/libvirt-gobject-connection.c: Populate URI
>   after opening connection, if NULL
> ---
>  libvirt-gobject/libvirt-gobject-connection.c |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
> index 59b828d..a1a6f5d 100644
> --- a/libvirt-gobject/libvirt-gobject-connection.c
> +++ b/libvirt-gobject/libvirt-gobject-connection.c
> @@ -415,6 +415,18 @@ gboolean gvir_connection_open(GVirConnection *conn,
>          return FALSE;
>      }
>  
> +    if (!priv->uri &&
> +        !(priv->uri = virConnectGetURI(priv->conn))) {

priv->uri will be freed with g_free(), virConnectGetURI must be freed with
free(), I'm afraid we'll have to g_strdup + free() here.

> +        if (err)
> +            *err = gvir_error_new(GVIR_CONNECTION_ERROR,
> +                                  0,
> +                                  "%s", "Unable to get connection URI");
> +        virConnectClose(priv->conn);
> +        priv->conn = NULL;
> +        g_mutex_unlock(priv->lock);
> +        return FALSE;
> +    }
> +
>      if (virConnectDomainEventRegister(priv->conn, domain_event_cb, conn, NULL) != -1)
>          priv->domain_event = TRUE;
>      else
> -- 
> 1.7.6.4
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20111130/9b22c4b7/attachment-0001.sig>


More information about the libvir-list mailing list