[virt-tools-list] [PATCH virt-viewer] SessionSpice: Protect against unreffing window twice

Jonathon Jongsma jjongsma at redhat.com
Tue Apr 14 20:28:49 UTC 2015


On Tue, 2015-04-14 at 14:40 -0500, Jonathon Jongsma wrote:
> In theory, the dispose method can be called multiple times, so any
> member variables that are unreffed should be set to NULL so that we
> don't accidentally unref them multiple times.
> ---
>  src/virt-viewer-session-spice.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
> index da193ec..40197b0 100644
> --- a/src/virt-viewer-session-spice.c
> +++ b/src/virt-viewer-session-spice.c
> @@ -146,7 +146,7 @@ virt_viewer_session_spice_dispose(GObject *obj)
>      spice->priv->audio = NULL;
>  
>      if (spice->priv->main_window)
> -        g_object_unref(spice->priv->main_window);
> +        g_clear_object(&spice->priv->main_window);
>  
>      G_OBJECT_CLASS(virt_viewer_session_spice_parent_class)->dispose(obj);
>  }

... and clearly I can just remove the if() check as long as I'm using
g_clear_object().




More information about the virt-tools-list mailing list