[virt-tools-list] [PATCH virt-viewer 1/2] VirtViewer: Fix memory leaks

Guido Günther agx at sigxcpu.org
Thu Sep 11 05:58:49 UTC 2014


On Wed, Sep 10, 2014 at 01:42:13PM -0500, Jonathon Jongsma wrote:
> Don't leak priv->uri or priv->domkey from VirtViewer class
> ---
>  src/virt-viewer.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/src/virt-viewer.c b/src/virt-viewer.c
> index c03503e..55780af 100644
> --- a/src/virt-viewer.c
> +++ b/src/virt-viewer.c
> @@ -518,6 +518,14 @@ virt_viewer_dispose (GObject *object)
>          virDomainFree(priv->dom);
>      if (priv->conn)
>          virConnectClose(priv->conn);
> +    if (priv->uri) {
> +        g_free(priv->uri);
> +        priv->uri = NULL;
> +    }
> +    if (priv->domkey) {
> +        g_free(priv->domkey);
> +        priv->domkey = NULL;
> +    }

g_free allows for a NULL poiner so there's no check necessary here:

       https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#g-free

Cheers
 -- Guido

>      G_OBJECT_CLASS(virt_viewer_parent_class)->dispose (object);
>  }
>  
> -- 
> 1.9.3
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
> 




More information about the virt-tools-list mailing list