1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-05 22:12:11 +00:00

Fix crash-on-exit reported by Gimp_ @ http://pastebin.ca/732759

This commit is contained in:
Charles Kerr 2007-10-11 14:56:50 +00:00
parent 7207e822fa
commit 00321c4eed

View file

@ -536,6 +536,31 @@ addCommonHeaders( const Tracker * t,
TR_NAME "/" LONG_VERSION_STRING ); TR_NAME "/" LONG_VERSION_STRING );
} }
/**
***
**/
struct torrent_hash
{
tr_handle * handle;
uint8_t hash[SHA_DIGEST_LENGTH];
};
static struct torrent_hash*
torrentHashNew( Torrent * tor )
{
struct torrent_hash * data = tr_new( struct torrent_hash, 1 );
data->handle = tor->tracker->handle;
memcpy( data->hash, tor->hash, SHA_DIGEST_LENGTH );
return data;
}
tr_torrent*
findTorrentFromHash( struct torrent_hash * data )
{
return tr_torrentFindFromHash( data->handle, data->hash );
}
/*** /***
**** ****
**** SCRAPE **** SCRAPE
@ -543,16 +568,22 @@ addCommonHeaders( const Tracker * t,
***/ ***/
static int static int
onTorrentScrapeNow( void * vtor ) onTorrentScrapeNow( void * vhash )
{ {
Torrent * tor = (Torrent *) vtor; tr_torrent * torrent = findTorrentFromHash( vhash );
if( trackerSupportsScrape( tor->tracker ) ) tr_free( vhash );
if( torrent != NULL )
{ {
if( tr_ptrArrayFindSorted( tor->tracker->scrapeQueue, tor, torrentCompare) == NULL ) Torrent * tor = torrent->tracker;
tr_ptrArrayInsertSorted( tor->tracker->scrapeQueue, tor, torrentCompare ); if( trackerSupportsScrape( tor->tracker ) )
tr_trackerScrapeSoon( tor->tracker ); {
if( tr_ptrArrayFindSorted( tor->tracker->scrapeQueue, tor, torrentCompare) == NULL )
tr_ptrArrayInsertSorted( tor->tracker->scrapeQueue, tor, torrentCompare );
tr_trackerScrapeSoon( tor->tracker );
}
tor->scrapeTimer = NULL;
} }
tor->scrapeTimer = NULL;
return FALSE; return FALSE;
} }
@ -613,7 +644,7 @@ onScrapeResponse( struct evhttp_request * req, void * primaryAddress )
tr_ptrArrayRemoveSorted( t->scraping, tor, torrentCompare ); tr_ptrArrayRemoveSorted( t->scraping, tor, torrentCompare );
tr_timerFree( &tor->scrapeTimer ); tr_timerFree( &tor->scrapeTimer );
tor->scrapeTimer = tr_timerNew( t->handle, onTorrentScrapeNow, tor, t->scrapeIntervalMsec ); tor->scrapeTimer = tr_timerNew( t->handle, onTorrentScrapeNow, torrentHashNew(tor), t->scrapeIntervalMsec );
tr_dbg( "Torrent '%s' scrape successful." tr_dbg( "Torrent '%s' scrape successful."
" Rescraping in %d seconds", " Rescraping in %d seconds",
tor->name, t->scrapeIntervalMsec/1000 ); tor->name, t->scrapeIntervalMsec/1000 );
@ -658,7 +689,7 @@ onScrapeResponse( struct evhttp_request * req, void * primaryAddress )
for( i=0; i<n; ++i ) { for( i=0; i<n; ++i ) {
if( errmsg != NULL ) if( errmsg != NULL )
publishErrorMessage( torrents[i], errmsg ); publishErrorMessage( torrents[i], errmsg );
onTorrentScrapeNow( torrents[i] ); onTorrentScrapeNow( torrentHashNew(torrents[i]) );
} }
tr_ptrArrayClear( t->scraping ); tr_ptrArrayClear( t->scraping );
} }
@ -838,39 +869,22 @@ setAnnounceInterval( Tracker * t,
static int onReannounceNow( void * vtor ); static int onReannounceNow( void * vtor );
struct response_user_data
{
tr_handle * handle;
uint8_t hash[SHA_DIGEST_LENGTH];
};
static struct response_user_data*
onTrackerResponseDataNew( Torrent * tor )
{
struct response_user_data * data = tr_new( struct response_user_data, 1 );
data->handle = tor->tracker->handle;
memcpy( data->hash, tor->hash, SHA_DIGEST_LENGTH );
return data;
}
static void static void
onStoppedResponse( struct evhttp_request * req UNUSED, void * handle UNUSED ) onStoppedResponse( struct evhttp_request * req UNUSED, void * handle UNUSED )
{ {
} }
static void static void
onTrackerResponse( struct evhttp_request * req, void * vdata ) onTrackerResponse( struct evhttp_request * req, void * torrent_hash )
{ {
char * errmsg; char * errmsg;
Torrent * tor; Torrent * tor;
int isStopped; int isStopped;
int reannounceInterval; int reannounceInterval;
struct response_user_data * data;
tr_torrent * t; tr_torrent * t;
data = vdata; t = findTorrentFromHash( torrent_hash );
t = tr_torrentFindFromHash( data->handle, data->hash ); tr_free( torrent_hash );
tr_free( data );
if( t == NULL ) /* torrent has been closed */ if( t == NULL ) /* torrent has been closed */
return; return;
@ -1010,7 +1024,7 @@ sendTrackerRequest( void * vt, const char * eventName )
httpReq = evhttp_request_new( onStoppedResponse, t->tracker->handle ); httpReq = evhttp_request_new( onStoppedResponse, t->tracker->handle );
} else { } else {
evhttp_connection_set_timeout( evcon, TIMEOUT_INTERVAL_SEC ); evhttp_connection_set_timeout( evcon, TIMEOUT_INTERVAL_SEC );
httpReq = evhttp_request_new( onTrackerResponse, onTrackerResponseDataNew(t) ); httpReq = evhttp_request_new( onTrackerResponse, torrentHashNew(t) );
} }
addCommonHeaders( t->tracker, httpReq ); addCommonHeaders( t->tracker, httpReq );
tr_evhttp_make_request( t->tracker->handle, evcon, tr_evhttp_make_request( t->tracker->handle, evcon,