From d9c1a2ebbbf395aa4d255b2a31f17ce8d0e2377a Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sun, 12 Jun 2011 11:27:34 +0100 Subject: [PATCH] script: Use a weak ref to remove the signal emission hook When an object goes away we should remove the emission hook for the state transitions, to avoid leaving hooks around. --- clutter/clutter-script.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c index 65ec23ee8..97fa04d7a 100644 --- a/clutter/clutter-script.c +++ b/clutter/clutter-script.c @@ -948,6 +948,8 @@ typedef struct { ClutterState *state; GObject *emitter; gchar *target; + gulong signal_id; + gulong hook_id; } HookData; typedef struct { @@ -985,6 +987,16 @@ clutter_script_state_change_hook (GSignalInvocationHint *ihint, return TRUE; } +static void +clutter_script_remove_state_change_hook (gpointer user_data, + GObject *object_p) +{ + HookData *hook_data = user_data; + + g_signal_remove_emission_hook (hook_data->signal_id, + hook_data->hook_id); +} + static void connect_each_object (gpointer key, gpointer value, @@ -1071,11 +1083,16 @@ connect_each_object (gpointer key, hook_data->emitter = object; hook_data->state = CLUTTER_STATE (state_object); hook_data->target = g_strdup (sinfo->target); + hook_data->signal_id = signal_id; + hook_data->hook_id = + g_signal_add_emission_hook (signal_id, signal_quark, + clutter_script_state_change_hook, + hook_data, + hook_data_free); - g_signal_add_emission_hook (signal_id, signal_quark, - clutter_script_state_change_hook, - hook_data, - hook_data_free); + g_object_weak_ref (hook_data->emitter, + clutter_script_remove_state_change_hook, + hook_data); } signal_info_free (sinfo);