[Spice-devel,spice-server,12/18] sound: Implement on_disconnect RedChannel callback

Submitted by Frediano Ziglio on Nov. 23, 2016, 6:07 p.m.

Details

Message ID 1479924452-15913-13-git-send-email-fziglio@redhat.com
State Superseded
Headers show
Series "Remove DummyChannel* objects" ( rev: 3 2 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Nov. 23, 2016, 6:07 p.m.
Avoid having dandling pointer to a client.

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

Patch hide | download patch | download mbox

diff --git a/server/sound.c b/server/sound.c
index 0c2a3ae..5ce028c 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -768,6 +768,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)
 {
@@ -1410,6 +1418,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