Changeset 3369


Ignore:
Timestamp:
Oct 11, 2007, 2:56:50 PM (14 years ago)
Author:
charles
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tracker.c

    r3341 r3369  
    537537}
    538538
     539/**
     540***
     541**/
     542
     543struct torrent_hash
     544{
     545    tr_handle * handle;
     546    uint8_t hash[SHA_DIGEST_LENGTH];
     547};
     548
     549static struct torrent_hash*
     550torrentHashNew( Torrent * tor )
     551{
     552    struct torrent_hash * data = tr_new( struct torrent_hash, 1 );
     553    data->handle = tor->tracker->handle;
     554    memcpy( data->hash, tor->hash, SHA_DIGEST_LENGTH );
     555    return data;
     556}
     557
     558tr_torrent*
     559findTorrentFromHash( struct torrent_hash * data )
     560{
     561    return tr_torrentFindFromHash( data->handle, data->hash );
     562}
     563
    539564/***
    540565****
     
    544569
    545570static int
    546 onTorrentScrapeNow( void * vtor )
    547 {
    548     Torrent * tor = (Torrent *) vtor;
    549     if( trackerSupportsScrape( tor->tracker ) )
    550     {
    551         if( tr_ptrArrayFindSorted( tor->tracker->scrapeQueue, tor, torrentCompare) == NULL )
    552             tr_ptrArrayInsertSorted( tor->tracker->scrapeQueue, tor, torrentCompare );
    553         tr_trackerScrapeSoon( tor->tracker );
    554     }
    555     tor->scrapeTimer = NULL;
     571onTorrentScrapeNow( void * vhash )
     572{
     573    tr_torrent * torrent = findTorrentFromHash( vhash );
     574    tr_free( vhash );
     575
     576    if( torrent != NULL )
     577    {
     578        Torrent * tor = torrent->tracker;
     579        if( trackerSupportsScrape( tor->tracker ) )
     580        {
     581            if( tr_ptrArrayFindSorted( tor->tracker->scrapeQueue, tor, torrentCompare) == NULL )
     582                tr_ptrArrayInsertSorted( tor->tracker->scrapeQueue, tor, torrentCompare );
     583            tr_trackerScrapeSoon( tor->tracker );
     584        }
     585        tor->scrapeTimer = NULL;
     586    }
    556587    return FALSE;
    557588}
     
    614645
    615646                tr_timerFree( &tor->scrapeTimer );
    616                 tor->scrapeTimer = tr_timerNew( t->handle, onTorrentScrapeNow, tor, t->scrapeIntervalMsec );
     647                tor->scrapeTimer = tr_timerNew( t->handle, onTorrentScrapeNow, torrentHashNew(tor), t->scrapeIntervalMsec );
    617648                tr_dbg( "Torrent '%s' scrape successful."
    618649                        "  Rescraping in %d seconds",
     
    659690            if( errmsg != NULL )
    660691                publishErrorMessage( torrents[i], errmsg );
    661             onTorrentScrapeNow( torrents[i] );
     692            onTorrentScrapeNow( torrentHashNew(torrents[i]) );
    662693        }
    663694        tr_ptrArrayClear( t->scraping );
     
    839870static int onReannounceNow( void * vtor );
    840871
    841 struct response_user_data
    842 {
    843     tr_handle * handle;
    844     uint8_t hash[SHA_DIGEST_LENGTH];
    845 };
    846 
    847 static struct response_user_data*
    848 onTrackerResponseDataNew( Torrent * tor )
    849 {
    850     struct response_user_data * data = tr_new( struct response_user_data, 1 );
    851     data->handle = tor->tracker->handle;
    852     memcpy( data->hash, tor->hash, SHA_DIGEST_LENGTH );
    853     return data;
    854 }
    855 
    856872static void
    857873onStoppedResponse( struct evhttp_request * req UNUSED, void * handle UNUSED )
     
    860876
    861877static void
    862 onTrackerResponse( struct evhttp_request * req, void * vdata )
     878onTrackerResponse( struct evhttp_request * req, void * torrent_hash )
    863879{
    864880    char * errmsg;
     
    866882    int isStopped;
    867883    int reannounceInterval;
    868     struct response_user_data * data;
    869884    tr_torrent * t;
    870885
    871     data = vdata;
    872     t = tr_torrentFindFromHash( data->handle, data->hash );
    873     tr_free( data );
     886    t = findTorrentFromHash( torrent_hash );
     887    tr_free( torrent_hash );
    874888    if( t == NULL ) /* torrent has been closed */
    875889        return;
     
    10111025        } else {
    10121026            evhttp_connection_set_timeout( evcon, TIMEOUT_INTERVAL_SEC );
    1013             httpReq = evhttp_request_new( onTrackerResponse, onTrackerResponseDataNew(t) );
     1027            httpReq = evhttp_request_new( onTrackerResponse, torrentHashNew(t) );
    10141028        }
    10151029        addCommonHeaders( t->tracker, httpReq );
Note: See TracChangeset for help on using the changeset viewer.