Changeset 3332


Ignore:
Timestamp:
Oct 8, 2007, 7:09:20 PM (14 years ago)
Author:
charles
Message:

fix crash reported by Waldorf in http://pastebin.ca/729980

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tracker.c

    r3331 r3332  
    260260
    261261static Tracker*
     262getExistingTracker( const char * primaryAddress )
     263{
     264    tr_ptrArray * trackers = getTrackerLookupTable( );
     265    Tracker tmp;
     266    assert( primaryAddress && *primaryAddress );
     267    tmp.primaryAddress = (char*) primaryAddress;
     268    return tr_ptrArrayFindSorted( trackers, &tmp, trackerCompare );
     269}
     270
     271static Tracker*
    262272tr_trackerGet( const tr_torrent * tor )
    263273{
    264274    const tr_info * info = &tor->info;
    265     tr_ptrArray * trackers = getTrackerLookupTable( );
    266     Tracker *t, tmp;
    267     assert( info != NULL );
    268     assert( info->primaryAddress && *info->primaryAddress );
    269     tmp.primaryAddress = info->primaryAddress;
    270     t = tr_ptrArrayFindSorted( trackers, &tmp, trackerCompare );
    271 
    272     assert( t==NULL || !strcmp(t->primaryAddress,info->primaryAddress) );
     275    Tracker * t = getExistingTracker( info->primaryAddress );
    273276
    274277    if( t == NULL ) /* no such tracker.... create one */
     
    317320        assert( iwalk - t->tierFronts == sum );
    318321
    319         tr_ptrArrayInsertSorted( trackers, t, trackerCompare );
     322        tr_ptrArrayInsertSorted( getTrackerLookupTable( ), t, trackerCompare );
    320323    }
    321324
     
    554557
    555558static void
    556 onScrapeResponse( struct evhttp_request * req, void * vt )
     559onScrapeResponse( struct evhttp_request * req, void * primaryAddress )
    557560{
    558561    char * errmsg;
    559     Tracker * t = (Tracker*) vt;
     562    Tracker * t;
    560563
    561564    tr_inf( "Got scrape response from  '%s': %s",
    562             t->primaryAddress,
     565            primaryAddress,
    563566            (req ? req->response_code_line : "(null)") );
     567
     568    t = getExistingTracker( primaryAddress );
     569    tr_free( primaryAddress );
     570    if( t == NULL ) /* tracker has been closed... */
     571        return;
    564572
    565573    if( req && ( req->response_code == HTTP_OK ) )
     
    710718        evcon = getConnection( t, address->address, address->port );
    711719        evhttp_connection_set_timeout( evcon, TIMEOUT_INTERVAL_SEC );
    712         req = evhttp_request_new( onScrapeResponse, t );
     720        req = evhttp_request_new( onScrapeResponse, tr_strdup(t->primaryAddress) );
    713721        assert( req );
    714722        addCommonHeaders( t, req );
Note: See TracChangeset for help on using the changeset viewer.