From 81785b563368adac8a3d2c20be8935ae723fd0f4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2008 13:06:59 +0000 Subject: [PATCH] #1126: crash on quit --- libtransmission/session.c | 2 +- libtransmission/tracker.c | 32 ++++++++++++++------------------ libtransmission/tracker.h | 2 +- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/libtransmission/session.c b/libtransmission/session.c index acac09f45..d9d85930e 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -497,7 +497,6 @@ tr_closeAllConnections( void * vh ) tr_torrent ** torrents; tr_sharedShuttingDown( h->shared ); - tr_trackerShuttingDown( h ); tr_rpcClose( &h->rpcServer ); /* close the torrents. get the most active ones first so that @@ -543,6 +542,7 @@ tr_sessionClose( tr_handle * h ) while( !h->isClosed && !deadlineReached( deadline ) ) tr_wait( 100 ); + tr_trackerSessionClose( h ); tr_list_free( &h->blocklists, (TrListForeachFunc)_tr_blocklistFree ); tr_webClose( &h->web ); diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index 4bbe380bd..d72485792 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -661,7 +661,6 @@ createScrape( tr_session * session, tr_tracker * tracker ) struct tr_tracker_handle { - unsigned int isShuttingDown : 1; int runningCount; tr_timer * pulseTimer; }; @@ -680,29 +679,15 @@ ensureGlobalsExist( tr_session * session ) } void -tr_trackerShuttingDown( tr_session * session ) +tr_trackerSessionClose( tr_session * session ) { - if( session->tracker ) - session->tracker->isShuttingDown = 1; -} - -static int -maybeFreeGlobals( tr_session * session ) -{ - int globalsExist = session->tracker != NULL; - - if( globalsExist - && ( session->tracker->runningCount < 1 ) - && ( session->torrentList== NULL ) ) + if( session && session->tracker ) { dbgmsg( NULL, "freeing tracker timer" ); tr_timerFree( &session->tracker->pulseTimer ); tr_free( session->tracker ); session->tracker = NULL; - globalsExist = FALSE; } - - return globalsExist; } /*** @@ -803,7 +788,18 @@ trackerPulse( void * vsession ) if( th->runningCount ) dbgmsg( NULL, "tracker pulse after upkeep... %d running", th->runningCount ); - return maybeFreeGlobals( session ); + /* free the tracker manager if no torrents are left */ + if( ( session->tracker ) + && ( session->tracker->runningCount < 1 ) + && ( session->torrentList == NULL ) ) + { + tr_trackerSessionClose( session ); + } + + /* if there are still running torrents (as indicated by + * the existence of the tracker manager) then keep the + * trackerPulse() timer alive */ + return session->tracker != NULL; } static void diff --git a/libtransmission/tracker.h b/libtransmission/tracker.h index 1ade23aac..3c65f4b08 100644 --- a/libtransmission/tracker.h +++ b/libtransmission/tracker.h @@ -27,7 +27,7 @@ tr_tracker * tr_trackerNew( const tr_torrent * ); void tr_trackerFree ( tr_tracker * ); -void tr_trackerShuttingDown( tr_handle * ); +void tr_trackerSessionClose( tr_handle * ); /** *** Tracker Publish / Subscribe