[virt-tools-list] [PATCH virt-viewer] spice: calling VirtViewerSession:close() can destroy self

Marc-André Lureau marcandre.lureau at gmail.com
Wed Nov 26 18:00:01 UTC 2014


ping

On Tue, Nov 25, 2014 at 12:57 PM, Marc-André Lureau
<marcandre.lureau at gmail.com> wrote:
> SpiceSession in spice-gtk v0.27 removes channels from session during
> disconnect (and not when they are actually disposed). When no channels
> are left, session-disconnected is emitted, and the VirtViewerSession
> will be unref from the application. Use a weak reference to self to
> avoid crashing after calling spice_session_disconnect()
>
> As a workaround for existing clients, spice-gtk v0.27 will defer the
> disconnection to idle time.  But the fix still makes sense and would
> prevent potentially future issues if spice-gtk changes back to sync
> disconnection.
>
> (the alternative of calling ref/unref would keep recreating session,
>  which is something it can avoid when leaving the application)
> ---
>  src/virt-viewer-session-spice.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
> index c459d96..ebe78fc 100644
> --- a/src/virt-viewer-session-spice.c
> +++ b/src/virt-viewer-session-spice.c
> @@ -292,16 +292,23 @@ virt_viewer_session_spice_close(VirtViewerSession *session)
>
>      g_return_if_fail(self != NULL);
>
> +    g_object_add_weak_pointer(G_OBJECT(self), (gpointer*)&self);
> +
>      virt_viewer_session_clear_displays(session);
>
>      if (self->priv->session) {
>          spice_session_disconnect(self->priv->session);
> +        if (!self)
> +            return;
> +
>          g_object_unref(self->priv->session);
>          self->priv->session = NULL;
>          self->priv->gtk_session = NULL;
>          self->priv->audio = NULL;
>      }
>
> +    g_object_remove_weak_pointer(G_OBJECT(self), (gpointer*)&self);
> +
>      /* FIXME: version 0.7 of spice-gtk allows reuse of session */
>      create_spice_session(self);
>  }
> --
> 2.1.0
>



-- 
Marc-André Lureau




More information about the virt-tools-list mailing list