[PATCH spice-gtk v2 12/19] coroutine: reference object when signaling

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

 



Before the signal is actually emitted, the channel may be
released. Let's keep a reference to the object during
the function time, to prevent the object from being destroyed before
calling g_signal_emit() in main context.
---
 gtk/gio-coroutine.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gtk/gio-coroutine.c b/gtk/gio-coroutine.c
index c903bd2..c866e15 100644
--- a/gtk/gio-coroutine.c
+++ b/gtk/gio-coroutine.c
@@ -222,9 +222,11 @@ g_coroutine_signal_emit(gpointer instance, guint signal_id,
     if (coroutine_self_is_main()) {
         g_signal_emit_valist(instance, signal_id, detail, data.var_args);
     } else {
+        g_object_ref(instance);
         g_idle_add(emit_main_context, &data);
         coroutine_yield(NULL);
         g_warn_if_fail(data.notified);
+        g_object_unref(instance);
     }
 
     va_end (data.var_args);
@@ -253,7 +255,7 @@ void g_coroutine_object_notify(GObject *object,
         g_object_notify(object, property_name);
     } else {
 
-        data.instance = object;
+        data.instance = g_object_ref(object);
         data.caller = coroutine_self();
         data.propname = (gpointer)property_name;
         data.notified = FALSE;
@@ -268,5 +270,6 @@ void g_coroutine_object_notify(GObject *object,
          */
         coroutine_yield(NULL);
         g_warn_if_fail(data.notified);
+        g_object_unref(object);
     }
 }
-- 
1.9.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://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]