From 6d5182af60b4f1fa2cc141fa96e1ff71ae807103 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 6 Oct 2007 01:43:04 +0000 Subject: [PATCH] fix potential "recheck torrent" deadlock --- libtransmission/inout.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libtransmission/inout.c b/libtransmission/inout.c index cd077a61c..1c69bfb19 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -402,19 +402,29 @@ compareRecheckByTorrent( const void * va, const void * vb ) void tr_ioRecheckRemove( tr_torrent * tor ) { - tr_lockLock( getRecheckLock( ) ); + tr_lock * lock = getRecheckLock( ); + tr_lockLock( lock ); - if( tor == currentNode.torrent ) { + if( tor == currentNode.torrent ) + { stopCurrent = TRUE; while( stopCurrent ) - tr_wait( 50 ); - } else { + { + tr_lockUnlock( lock ); + tr_wait( 100 ); + tr_lockLock( lock ); + } + } + else + { struct recheck_node tmp; tmp.torrent = tor; - struct recheck_node * node = tr_list_remove( &recheckList, &tmp, compareRecheckByTorrent ); + struct recheck_node * node = tr_list_remove( &recheckList, + &tmp, + compareRecheckByTorrent ); tr_free( node ); tor->recheckState = TR_RECHECK_NONE; } - tr_lockUnlock( getRecheckLock( ) ); + tr_lockUnlock( lock ); }