[virt-tools-list] [PATCH virt-viewer 2/9] spice: calling VirtViewerSession:close() can destroy self
Marc-André Lureau
marcandre.lureau at gmail.com
Thu Nov 13 17:20:38 UTC 2014
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;
--
1.9.3
More information about the virt-tools-list
mailing list