[spice-server,v2,4/7] red-client: Make sure MainChannelClient is freed as last

Submitted by Frediano Ziglio on Oct. 14, 2019, 9:22 a.m.

Details

Message ID 20191014092217.24405-5-fziglio@redhat.com
State New
Headers show
Series "Thread and Smartcard" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Oct. 14, 2019, 9:22 a.m.
MainChannelClient is used by other clients to store some data
so should not disappear if other clients are still present.
Keep a owning reference to it and release after RedClient is
released.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 server/red-client.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/server/red-client.c b/server/red-client.c
index d73d0f8d0..476f6f5be 100644
--- a/server/red-client.c
+++ b/server/red-client.c
@@ -106,6 +106,7 @@  red_client_finalize (GObject *object)
 {
     RedClient *self = RED_CLIENT(object);
 
+    g_clear_object(&self->mcc);
     spice_debug("release client=%p", self);
     pthread_mutex_destroy(&self->lock);
 
@@ -313,7 +314,8 @@  MainChannelClient *red_client_get_main(RedClient *client)
 
 void red_client_set_main(RedClient *client, MainChannelClient *mcc)
 {
-    client->mcc = mcc;
+    spice_assert(client->mcc == NULL);
+    client->mcc = g_object_ref(mcc);
 }
 
 void red_client_semi_seamless_migrate_complete(RedClient *client)