[virt-tools-list] [virt-viewer][PATCH 1/3] Make sure conn exists before use it

Christophe Fergeau cfergeau at redhat.com
Wed Nov 19 11:59:08 UTC 2014


Hey,

On Wed, Nov 19, 2014 at 05:58:21AM +0100, Fabiano Fidêncio wrote:
> Although all the used functions have a explicit check for a valid
> virConnPtr, let's be safe and only use priv->conn when its value is
> non-NULL.

Yup, makes sense/looks good, though I'd add priv->conn = NULL and priv-dom = NULL
(this one in a separate patch) for good measure.
ACK.

Christophe


> 
> Related to: rhbz#1164052
> https://bugzilla.redhat.com/show_bug.cgi?id=1164052
> ---
>  src/virt-viewer.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/src/virt-viewer.c b/src/virt-viewer.c
> index dc16b3f..9fa2a80 100644
> --- a/src/virt-viewer.c
> +++ b/src/virt-viewer.c
> @@ -529,15 +529,16 @@ virt_viewer_dispose (GObject *object)
>      VirtViewer *self = VIRT_VIEWER(object);
>      VirtViewerPrivate *priv = self->priv;
>  
> -    if (priv->withEvents)
> -        virConnectDomainEventDeregister(priv->conn,
> -                                        virt_viewer_domain_event);
> -    virConnectUnregisterCloseCallback(priv->conn,
> -                                      virt_viewer_conn_event);
> +    if (priv->conn) {
> +        if (priv->withEvents)
> +            virConnectDomainEventDeregister(priv->conn,
> +                                            virt_viewer_domain_event);
> +        virConnectUnregisterCloseCallback(priv->conn,
> +                                          virt_viewer_conn_event);
> +        virConnectClose(priv->conn);
> +    }
>      if (priv->dom)
>          virDomainFree(priv->dom);
> -    if (priv->conn)
> -        virConnectClose(priv->conn);
>      g_free(priv->uri);
>      priv->uri = NULL;
>      g_free(priv->domkey);
> -- 
> 2.1.0
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20141119/7cb729b9/attachment.sig>


More information about the virt-tools-list mailing list