mirror of
https://github.com/transmission/transmission
synced 2024-12-26 09:37:56 +00:00
fix the crash reported by Waldorf and John_Clay
This commit is contained in:
parent
53aef0a48c
commit
0872b4f40a
4 changed files with 38 additions and 9 deletions
|
@ -576,6 +576,7 @@ readHandshake( tr_handshake * handshake, struct evbuffer * inbuf )
|
|||
uint8_t * pstr;
|
||||
uint8_t reserved[HANDSHAKE_FLAGS_LEN];
|
||||
uint8_t hash[SHA_DIGEST_LENGTH];
|
||||
char * client;
|
||||
|
||||
/* FIXME: use readHandshake here */
|
||||
|
||||
|
@ -666,7 +667,9 @@ readHandshake( tr_handshake * handshake, struct evbuffer * inbuf )
|
|||
tr_peerIoReadBytes( handshake->io, inbuf, handshake->peer_id, sizeof(handshake->peer_id) );
|
||||
tr_peerIoSetPeersId( handshake->io, handshake->peer_id );
|
||||
handshake->havePeerID = TRUE;
|
||||
dbgmsg( handshake, "peer-id is [%s]", tr_clientForId(handshake->peer_id) );
|
||||
client = tr_clientForId( handshake->peer_id );
|
||||
dbgmsg( handshake, "peer-id is [%s]", client );
|
||||
tr_free( client );
|
||||
if( !memcmp( handshake->peer_id, getPeerId(), PEER_ID_LEN ) ) {
|
||||
dbgmsg( handshake, "streuth! we've connected to ourselves." );
|
||||
tr_handshakeDone( handshake, FALSE );
|
||||
|
|
|
@ -404,6 +404,7 @@ torrentDestructor( Torrent * t )
|
|||
tr_bitfieldFree( t->requested );
|
||||
tr_ptrArrayFree( t->pool, (PtrArrayForeachFunc)tr_free );
|
||||
tr_ptrArrayFree( t->outgoingHandshakes, NULL );
|
||||
tr_ptrArrayFree( t->peers, NULL );
|
||||
|
||||
tr_free( t );
|
||||
}
|
||||
|
|
|
@ -737,9 +737,7 @@ onTrackerScrapeNow( void * vt )
|
|||
static int
|
||||
torrentIsRunning( const Torrent * tor )
|
||||
{
|
||||
return ( tor != NULL )
|
||||
&& ( tor->lastRequest != NULL )
|
||||
&& ( strcmp( tor->lastRequest, "stopped" ) );
|
||||
return tor && tor->isRunning;
|
||||
}
|
||||
|
||||
static char*
|
||||
|
@ -840,13 +838,39 @@ setAnnounceInterval( Tracker * t,
|
|||
|
||||
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
|
||||
onTrackerResponse( struct evhttp_request * req, void * vtor )
|
||||
onTrackerResponse( struct evhttp_request * req, void * vdata )
|
||||
{
|
||||
char * errmsg;
|
||||
Torrent * tor = (Torrent *) vtor;
|
||||
const int isStopped = !torrentIsRunning( tor );
|
||||
Torrent * tor;
|
||||
int isStopped;
|
||||
int reannounceInterval;
|
||||
struct response_user_data * data;
|
||||
tr_torrent * t;
|
||||
|
||||
data = vdata;
|
||||
t = tr_torrentFindFromHash( data->handle, data->hash );
|
||||
tr_free( data );
|
||||
if( t == NULL ) /* torrent has been closed */
|
||||
return;
|
||||
|
||||
tor = t->tracker;
|
||||
isStopped = !torrentIsRunning( tor );
|
||||
|
||||
tr_inf( "Torrent \"%s\" tracker response: %s",
|
||||
tor->name,
|
||||
|
@ -976,7 +1000,7 @@ sendTrackerRequest( void * vt, const char * eventName )
|
|||
tr_free( t->lastRequest );
|
||||
t->lastRequest = tr_strdup( eventName );
|
||||
evhttp_connection_set_timeout( evcon, REQ_TIMEOUT_INTERVAL_SEC );
|
||||
httpReq = evhttp_request_new( onTrackerResponse, t );
|
||||
httpReq = evhttp_request_new( onTrackerResponse, onTrackerResponseDataNew(t) );
|
||||
addCommonHeaders( t->tracker, httpReq );
|
||||
tr_evhttp_make_request( t->tracker->handle, evcon,
|
||||
httpReq, EVHTTP_REQ_GET, uri );
|
||||
|
|
|
@ -685,7 +685,8 @@ tr_malloc0( size_t size )
|
|||
return ret;
|
||||
}
|
||||
|
||||
void tr_free( void * p )
|
||||
void
|
||||
tr_free( void * p )
|
||||
{
|
||||
if( p )
|
||||
free( p );
|
||||
|
|
Loading…
Reference in a new issue