summaryrefslogtreecommitdiffstats
path: root/server/red_channel.c
diff options
context:
space:
mode:
authorYonit Halperin <yhalperi@redhat.com>2013-07-26 13:45:16 -0400
committerYonit Halperin <yhalperi@redhat.com>2013-07-29 11:35:16 -0400
commitaab45618cc12799d5f7351ef8832ae73b33057c7 (patch)
treed790a3bcc20c8b69f0224e0f20e869094bc1fbb2 /server/red_channel.c
parent47e722b85ccd0b6876ca189a3d6f6f05289fe3c3 (diff)
downloadspice-aab45618cc12799d5f7351ef8832ae73b33057c7.tar.gz
spice-aab45618cc12799d5f7351ef8832ae73b33057c7.tar.xz
spice-aab45618cc12799d5f7351ef8832ae73b33057c7.zip
red_channel: add ref count to RedClient
Diffstat (limited to 'server/red_channel.c')
-rw-r--r--server/red_channel.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/server/red_channel.c b/server/red_channel.c
index 0d74413e..9168b8ad 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -1932,10 +1932,29 @@ RedClient *red_client_new(int migrated)
pthread_mutex_init(&client->lock, NULL);
client->thread_id = pthread_self();
client->during_target_migrate = migrated;
+ client->refs = 1;
return client;
}
+RedClient *red_client_ref(RedClient *client)
+{
+ spice_assert(client);
+ client->refs++;
+ return client;
+}
+
+RedClient *red_client_unref(RedClient *client)
+{
+ if (!--client->refs) {
+ spice_debug("release client=%p", client);
+ pthread_mutex_destroy(&client->lock);
+ free(client);
+ return NULL;
+ }
+ return client;
+}
+
/* client mutex should be locked before this call */
static void red_channel_client_set_migration_seamless(RedChannelClient *rcc)
{
@@ -2012,9 +2031,7 @@ void red_client_destroy(RedClient *client)
spice_assert(rcc->send_data.size == 0);
red_channel_client_destroy(rcc);
}
-
- pthread_mutex_destroy(&client->lock);
- free(client);
+ red_client_unref(client);
}
/* client->lock should be locked */