Changeset 11831


Ignore:
Timestamp:
Feb 5, 2011, 5:03:00 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) #3980 "segfault when adding many torrents remotely" -- possible fix.

gtk/main.c's onRPCChanged() is called from inside the libtransmission thread, yet it still made GTK+ calls to modify the GTK+ client's tr-core object when a torrent was added. This caused a race condition inside of the GTK+ internals. onRPCChanged() already knows to delegate work back to the GTK+ thread when a torrent is removed via RPC. This commit uses the same kind of mechanism to delegate work back to the GTK+ thread when a torrent is added via RPC.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r11805 r11831  
    450450}
    451451
    452 struct remove_torrent_idle_data
     452struct torrent_idle_data
    453453{
    454454    TrCore * core;
     
    457457
    458458static gboolean
    459 remove_torrent_idle( gpointer gdata )
    460 {
    461     struct remove_torrent_idle_data * data = gdata;
     459rpc_torrent_remove_idle( gpointer gdata )
     460{
     461    struct torrent_idle_data * data = gdata;
     462
    462463    tr_core_remove_torrent_from_id( data->core, data->id, FALSE );
     464
    463465    g_free( data );
    464466    return FALSE; /* tell g_idle not to call this func twice */
    465467}
     468
     469static gboolean
     470rpc_torrent_add_idle( gpointer gdata )
     471{
     472    tr_torrent * tor;
     473    struct torrent_idle_data * data = gdata;
     474
     475    if(( tor = tr_torrentFindFromId( tr_core_session( data->core ), data->id )))
     476        tr_core_add_torrent( data->core, tr_torrent_new_preexisting( tor ), TRUE );
     477
     478    g_free( data );
     479    return FALSE; /* tell g_idle not to call this func twice */
     480}
     481
    466482
    467483static void
     
    488504            break;
    489505
    490         case TR_RPC_TORRENT_ADDED:
    491             tr_core_add_torrent( cbdata->core, tr_torrent_new_preexisting( tor ), TRUE );
    492             break;
    493 
    494         case TR_RPC_TORRENT_REMOVING: {
    495             struct remove_torrent_idle_data * data = g_new0( struct remove_torrent_idle_data, 1 );
     506        case TR_RPC_TORRENT_ADDED: {
     507            struct torrent_idle_data * data = g_new0( struct torrent_idle_data, 1 );
    496508            data->id = tr_torrentId( tor );
    497509            data->core = cbdata->core;
    498             gtr_idle_add( remove_torrent_idle, data );
     510            gtr_idle_add( rpc_torrent_add_idle, data );
     511            break;
     512        }
     513
     514        case TR_RPC_TORRENT_REMOVING: {
     515            struct torrent_idle_data * data = g_new0( struct torrent_idle_data, 1 );
     516            data->id = tr_torrentId( tor );
     517            data->core = cbdata->core;
     518            gtr_idle_add( rpc_torrent_remove_idle, data );
    499519            status = TR_RPC_NOREMOVE;
    500520            break;
Note: See TracChangeset for help on using the changeset viewer.