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

Submitted by Frediano Ziglio on Nov. 29, 2016, 2:57 p.m.

Details

Message ID 0cbd5daabbf8530569113464089042beee342434.1480431431.git-series.fziglio@redhat.com
State Accepted
Headers show
Series "Remove DummyChannel* objects" ( rev: 4 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Nov. 29, 2016, 2:57 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 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