[Spice-devel] [PATCH spice-server] fixup! Re-arrange channel client creation to avoid exposing client lock

Frediano Ziglio fziglio at redhat.com
Tue Nov 1 15:37:52 UTC 2016


Call red_client_add_channel at the end of initialisation.
This respect the previous order.
After returning from a successful red_client_add_channel another
thread could call some function in this RedChannelClient so make sure
is fully initalized. Not doing so for instance could cause a
disconnection to a freed RedChannelClient to be scheduled.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/dummy-channel-client.c | 6 ++----
 server/red-channel-client.c   | 6 +++---
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/server/dummy-channel-client.c b/server/dummy-channel-client.c
index a39941c..c602412 100644
--- a/server/dummy-channel-client.c
+++ b/server/dummy-channel-client.c
@@ -44,13 +44,11 @@ static gboolean dummy_channel_client_initable_init(GInitable *initable,
     RedClient *client = red_channel_client_get_client(rcc);
     RedChannel *channel = red_channel_client_get_channel(rcc);
 
+    red_channel_add_client(channel, rcc);
     if (!red_client_add_channel(client, rcc, &local_error)) {
-        goto cleanup;
+        red_channel_remove_client(channel, rcc);
     }
 
-    red_channel_add_client(channel, rcc);
-
-cleanup:
     if (local_error) {
         g_warning("Failed to create channel client: %s", local_error->message);
         g_propagate_error(error, local_error);
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 5a462dc..bfa44b4 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -869,9 +869,6 @@ static gboolean red_channel_client_initable_init(GInitable *initable,
     GError *local_error = NULL;
     SpiceCoreInterfaceInternal *core;
     RedChannelClient *self = RED_CHANNEL_CLIENT(initable);
-    if (!red_client_add_channel(self->priv->client, self, &local_error)) {
-        goto cleanup;
-    }
 
     if (!red_channel_config_socket(self->priv->channel, self)) {
         g_set_error_literal(&local_error,
@@ -902,6 +899,9 @@ static gboolean red_channel_client_initable_init(GInitable *initable,
     }
 
     red_channel_add_client(self->priv->channel, self);
+    if (!red_client_add_channel(self->priv->client, self, &local_error)) {
+        red_channel_remove_client(self->priv->channel, self);
+    }
 
 cleanup:
     if (local_error) {
-- 
2.7.4



More information about the Spice-devel mailing list