[Spice-devel] [PATCH v3 11/17] sound: Implement on_disconnect RedChannel callback

Frediano Ziglio fziglio at redhat.com
Tue Nov 29 14:57:11 UTC 2016


Avoid having dandling pointer to a client.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/sound.c |  9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/server/sound.c b/server/sound.c
index 24fd729..4906122 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -773,6 +773,14 @@ static int snd_channel_config_socket(RedChannelClient *rcc)
     return TRUE;
 }
 
+static void snd_channel_on_disconnect(RedChannelClient *rcc)
+{
+    SndChannel *channel = SND_CHANNEL(red_channel_client_get_channel(rcc));
+    if (channel->connection && rcc == RED_CHANNEL_CLIENT(channel->connection)) {
+        channel->connection = NULL;
+    }
+}
+
 static uint8_t*
 snd_channel_client_alloc_recv_buf(RedChannelClient *rcc, uint16_t type, uint32_t size)
 {
@@ -1415,6 +1423,7 @@ snd_channel_class_init(SndChannelClass *klass)
     channel_class->config_socket = snd_channel_config_socket;
     channel_class->alloc_recv_buf = snd_channel_client_alloc_recv_buf;
     channel_class->release_recv_buf = snd_channel_client_release_recv_buf;
+    channel_class->on_disconnect = snd_channel_on_disconnect;
 }
 
 static void
-- 
git-series 0.9.1


More information about the Spice-devel mailing list