[PATCH 3/9] RedsState: keep weak reference to channels

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Keep a weak references to all registered channels, and free the list of
channels upon destruction.
---
 server/reds.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/server/reds.c b/server/reds.c
index c2ac4d9..9034197 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -452,9 +452,16 @@ void stat_remove_counter(RedsState *reds, uint64_t *counter)
 }
 #endif
 
+static void reds_channel_destroyed(gpointer data, GObject *ex_object)
+{
+    RedsState *reds = data;
+    reds->channels = g_list_remove(reds->channels, ex_object);
+}
+
 void reds_register_channel(RedsState *reds, RedChannel *channel)
 {
     spice_assert(reds);
+    g_object_weak_ref(G_OBJECT(channel), reds_channel_destroyed, reds);
     reds->channels = g_list_prepend(reds->channels, channel);
 }
 
@@ -3676,9 +3683,16 @@ SPICE_GNUC_VISIBLE int spice_server_init(SpiceServer *reds, SpiceCoreInterface *
 
 SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer *reds)
 {
+    GList *l;
+
     g_array_unref(reds->config->renderers);
     g_array_unref(reds->config->video_codecs);
     free(reds->config);
+
+    for (l = reds->channels; l != NULL; l = l->next)
+        g_object_weak_unref(l->data, reds_channel_destroyed, reds);
+    g_list_free(reds->channels);
+
     if (reds->main_channel) {
         main_channel_close(reds->main_channel);
         g_object_unref(reds->main_channel);
-- 
2.7.4

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]