From add9eda736af5f0b637bbc4966cb130924026ad0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 6 Oct 2008 20:35:48 +0000 Subject: [PATCH] (gtk) fix prefs dialog crash when closing the dialog immediately after changing a spinbox value, reported by wereHamster --- gtk/tr-prefs.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index a6a12e61e..61d84a800 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -197,6 +197,7 @@ new_check_button( const char * mnemonic, struct spin_idle_data { + guint tag; gpointer core; GTimer * last_change; }; @@ -210,11 +211,18 @@ spin_idle_data_free( gpointer gdata ) g_free( data ); } +static void +onSpinDestroyed( gpointer tag, + GObject * details UNUSED ) +{ + g_source_remove( GPOINTER_TO_UINT( tag ) ); +} + static gboolean spun_cb_idle( gpointer spin ) { - gboolean keep_waiting = TRUE; - GObject * o = G_OBJECT( spin ); + gboolean keep_waiting = TRUE; + GObject * o = G_OBJECT( spin ); struct spin_idle_data * data = g_object_get_data( o, IDLE_DATA ); /* has the user stopped making changes? */ @@ -227,6 +235,7 @@ spun_cb_idle( gpointer spin ) tr_core_set_pref_int( TR_CORE( data->core ), key, value ); /* cleanup */ + g_object_weak_unref( o, onSpinDestroyed, GUINT_TO_POINTER( data->tag ) ); g_object_set_data( o, IDLE_DATA, NULL ); keep_waiting = FALSE; } @@ -248,8 +257,9 @@ spun_cb( GtkSpinButton * w, data = g_new( struct spin_idle_data, 1 ); data->core = core; data->last_change = g_timer_new( ); + data->tag = g_timeout_add( 100, spun_cb_idle, w ); g_object_set_data_full( o, IDLE_DATA, data, spin_idle_data_free ); - g_timeout_add( 100, spun_cb_idle, w ); + g_object_weak_ref( o, onSpinDestroyed, GUINT_TO_POINTER( data->tag ) ); } g_timer_start( data->last_change ); }