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

Marc-André Lureau marcandre.lureau at gmail.com
Fri Nov 14 14:18:22 UTC 2014


On Thu, Nov 13, 2014 at 6:20 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 | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/src/virt-viewer-session-spice.c
> b/src/virt-viewer-session-spice.c
> index 2eb2224..afeeadd 100644
> --- a/src/virt-viewer-session-spice.c
> +++ b/src/virt-viewer-session-spice.c
> @@ -292,10 +292,15 @@ 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;
>

It's missing g_object_remove_weak_pointer() which I just added.


> --
> 1.9.3
>
>


-- 
Marc-André Lureau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20141114/0445a622/attachment.htm>


More information about the virt-tools-list mailing list