From 1bd9dd04b8991325b35e582269c5f413077a805e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 2 Oct 2008 16:42:35 +0000 Subject: [PATCH] (gtk) #1290: removing torrent in web/remote interface crashes GTK+ client --- gtk/main.c | 47 ++++++++++++----------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/gtk/main.c b/gtk/main.c index 09bc53616..9920e6a3e 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -309,25 +309,20 @@ setupsighandlers( void ) signal( sigs[i], fatalsig ); } -struct rpc_data +static tr_rpc_callback_status +onRPCChanged( tr_handle * handle UNUSED, + tr_rpc_callback_type type, + struct tr_torrent * tor, + void * gdata ) { - int type; - int torrentId; - tr_torrent * tor; - struct cbdata * cbdata; -}; + struct cbdata * cbdata = gdata; + gdk_threads_enter( ); -static int -onRPCIdle( void * vdata ) -{ - struct rpc_data * data = vdata; - - switch( data->type ) + switch( type ) { case TR_RPC_TORRENT_ADDED: - tr_core_add_torrent( data->cbdata->core, - tr_torrent_new_preexisting( - data->tor ) ); + tr_core_add_torrent( cbdata->core, + tr_torrent_new_preexisting( tor ) ); break; case TR_RPC_TORRENT_STARTED: @@ -339,7 +334,7 @@ onRPCIdle( void * vdata ) break; case TR_RPC_TORRENT_REMOVING: - tr_core_torrent_destroyed( data->cbdata->core, data->torrentId ); + tr_core_torrent_destroyed( cbdata->core, tr_torrentId( tor ) ); break; case TR_RPC_TORRENT_CHANGED: @@ -347,26 +342,8 @@ onRPCIdle( void * vdata ) /* nothing interesting to do here */ break; } - g_free( data ); - return FALSE; -} -static tr_rpc_callback_status -onRPCChanged( tr_handle * handle UNUSED, - tr_rpc_callback_type type, - struct tr_torrent * tor, - void * cbdata ) -{ - /* this callback is being invoked from the libtransmission thread, - * so let's push the information over to the gtk+ thread where - * it's safe to update the gui */ - struct rpc_data * data = g_new0( struct rpc_data, 1 ); - - data->type = type; - data->torrentId = tor ? tr_torrentId( tor ) : -1; - data->tor = type == TR_RPC_TORRENT_REMOVING ? NULL : tor; - data->cbdata = cbdata; - g_idle_add( onRPCIdle, data ); + gdk_threads_leave( ); return TR_RPC_OK; }