Changeset 3217


Ignore:
Timestamp:
Sep 28, 2007, 2:27:56 PM (14 years ago)
Author:
charles
Message:

fix a couple of memory corruption errors while trying to track down tiennou's report on peer-msgs.c:pulse() -> inout.c:163 assertion failure.

Location:
trunk/libtransmission
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/list.c

    r3105 r3217  
    3232
    3333void
    34 tr_list_free( tr_list** list )
     34tr_list_free( tr_list** list, TrListForeachFunc data_free_func )
    3535{
    3636    while( *list )
    3737    {
    38         tr_list * node = *list;
     38        tr_list *node = *list;
    3939        *list = (*list)->next;
     40        if( data_free_func != NULL )
     41            data_free_func( node->data );
    4042        node_free( node );
    4143    }
  • trunk/libtransmission/list.h

    r3105 r3217  
    2727int         tr_list_size           ( const tr_list    * list );
    2828
    29 void        tr_list_free           ( tr_list         ** list );
     29void        tr_list_free           ( tr_list         ** list,
     30                                     TrListForeachFunc  data_free_func );
    3031
    3132void        tr_list_append         ( tr_list         ** list,
  • trunk/libtransmission/peer-msgs.c

    r3197 r3217  
    301301    {
    302302        msgs->info->peerIsChoked = choke ? 1 : 0;
    303         if( msgs->info )
    304         {
    305             tr_list_foreach( msgs->peerAskedFor, tr_free );
    306             tr_list_free( &msgs->peerAskedFor );
    307         }
     303
     304        if( choke )
     305            tr_list_free( &msgs->peerAskedFor, tr_free );
    308306
    309307        dbgmsg( msgs, "sending a %s message", (choke ? "CHOKE" : "UNCHOKE") );
     
    329327    assert( length > 0 );
    330328
     329    /* have we asked the peer for this piece? */
    331330    tmp.index = pieceIndex;
    332331    tmp.offset = offset;
    333332    tmp.length = length;
    334 
    335     node = tr_list_find( msgs->clientAskedFor, &tmp, peer_request_compare );
    336     if( node != NULL )
    337     {
    338         /* cancel the request */
     333    node = tr_list_remove( &msgs->clientAskedFor, &tmp, peer_request_compare );
     334
     335    /* if so, send a cancel message */
     336    if( node != NULL ) {
    339337        tr_peerIoWriteUint32( msgs->io, msgs->outMessages, sizeof(uint8_t) + 3*sizeof(uint32_t) );
    340338        tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages, BT_CANCEL );
     
    342340        tr_peerIoWriteUint32( msgs->io, msgs->outMessages, offset );
    343341        tr_peerIoWriteUint32( msgs->io, msgs->outMessages, length );
    344 
    345         /* remove it from our "requested" list */
    346         tr_list_remove_data( &msgs->peerAskedFor, node->data );
     342        tr_free( node );
    347343    }
    348344}
     
    634630    {
    635631        case BT_CHOKE:
     632            dbgmsg( msgs, "w00t peer sent us a BT_CHOKE" );
    636633            assert( msglen == 0 );
    637             dbgmsg( msgs, "w00t peer sent us a BT_CHOKE" );
    638634            msgs->info->clientIsChoked = 1;
    639             tr_list_foreach( msgs->peerAskedFor, tr_free );
    640             tr_list_free( &msgs->peerAskedFor );
    641             tr_list_foreach( msgs->clientAskedFor, tr_free );
    642             tr_list_free( &msgs->clientAskedFor );
     635            tr_list_free( &msgs->peerAskedFor, tr_free );
     636            tr_list_free( &msgs->clientAskedFor, tr_free );
    643637            break;
    644638
    645639        case BT_UNCHOKE:
     640            dbgmsg( msgs, "w00t peer sent us a BT_UNCHOKE" );
    646641            assert( msglen == 0 );
    647             dbgmsg( msgs, "w00t peer sent us a BT_UNCHOKE" );
    648642            msgs->info->clientIsChoked = 0;
    649643            fireNeedReq( msgs );
     
    651645
    652646        case BT_INTERESTED:
     647            dbgmsg( msgs, "w00t peer sent us a BT_INTERESTED" );
    653648            assert( msglen == 0 );
    654             dbgmsg( msgs, "w00t peer sent us a BT_INTERESTED" );
    655649            msgs->info->peerIsInterested = 1;
    656650            break;
    657651
    658652        case BT_NOT_INTERESTED:
     653            dbgmsg( msgs, "w00t peer sent us a BT_NOT_INTERESTED" );
    659654            assert( msglen == 0 );
    660             dbgmsg( msgs, "w00t peer sent us a BT_NOT_INTERESTED" );
    661655            msgs->info->peerIsInterested = 0;
    662656            break;
    663657
    664658        case BT_HAVE:
     659            dbgmsg( msgs, "w00t peer sent us a BT_HAVE" );
    665660            assert( msglen == 4 );
    666             dbgmsg( msgs, "w00t peer sent us a BT_HAVE" );
    667661            tr_peerIoReadUint32( msgs->io, inbuf, &ui32 );
    668662            tr_bitfieldAdd( msgs->info->have, ui32 );
     
    674668
    675669        case BT_BITFIELD:
     670            dbgmsg( msgs, "w00t peer sent us a BT_BITFIELD" );
    676671            assert( msglen == msgs->info->have->len );
    677             dbgmsg( msgs, "w00t peer sent us a BT_BITFIELD" );
    678672            tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, msglen );
    679673            msgs->info->progress = tr_bitfieldCountTrueBits( msgs->info->have ) / (float)msgs->torrent->info.pieceCount;
     
    686680        case BT_REQUEST: {
    687681            struct peer_request * req;
     682            dbgmsg( msgs, "peer sent us a BT_REQUEST" );
    688683            assert( msglen == 12 );
    689             dbgmsg( msgs, "peer sent us a BT_REQUEST" );
    690684            req = tr_new( struct peer_request, 1 );
    691685            tr_peerIoReadUint32( msgs->io, inbuf, &req->index );
     
    702696            struct peer_request req;
    703697            void * data;
     698            dbgmsg( msgs, "peer sent us a BT_CANCEL" );
    704699            assert( msglen == 12 );
    705             dbgmsg( msgs, "peer sent us a BT_CANCEL" );
    706700            tr_peerIoReadUint32( msgs->io, inbuf, &req.index );
    707701            tr_peerIoReadUint32( msgs->io, inbuf, &req.offset );
     
    726720
    727721        case BT_PORT: {
     722            dbgmsg( msgs, "peer sent us a BT_PORT" );
    728723            assert( msglen == 2 );
    729             dbgmsg( msgs, "peer sent us a BT_PORT" );
    730724            tr_peerIoReadUint16( msgs->io, inbuf, &msgs->info->port );
    731725            break;
     
    10711065        uint8_t * tmp = tr_new( uint8_t, req->length );
    10721066        const uint32_t msglen = sizeof(uint8_t) + 2*sizeof(uint32_t) + req->length;
     1067        assert( requestIsValid( msgs, req ) );
    10731068        tr_ioRead( msgs->torrent, req->index, req->offset, req->length, tmp );
    10741069        tr_peerIoWriteUint32( msgs->io, msgs->outBlock, msglen );
     
    13211316        tr_timerFree( &msgs->pexTimer );
    13221317        tr_publisherFree( &msgs->publisher );
    1323         tr_list_foreach( msgs->clientAskedFor, tr_free );
    1324         tr_list_free( &msgs->clientAskedFor );
    1325         tr_list_foreach( msgs->peerAskedFor, tr_free );
    1326         tr_list_free( &msgs->peerAskedFor );
     1318        tr_list_free( &msgs->clientAskedFor, tr_free );
     1319        tr_list_free( &msgs->peerAskedFor, tr_free );
    13271320        evbuffer_free( msgs->outMessages );
    13281321        evbuffer_free( msgs->outBlock );
  • trunk/libtransmission/peer.c

    r3111 r3217  
    360360    tr_bitfieldFree( peer->banfield );
    361361    tr_bitfieldFree( peer->reqfield );
    362     tr_list_foreach( peer->outRequests, tr_free );
    363     tr_list_free( &peer->outRequests );
     362    tr_list_free( &peer->outRequests, tr_free );
    364363    tr_free( peer->inRequests );
    365364    tr_free( peer->buf );
  • trunk/libtransmission/platform.c

    r3105 r3217  
    411411    delete_sem( c->sem );
    412412#elif defined(WIN32)
    413     tr_list_free( &c->events );
     413    tr_list_free( &c->events, NULL );
    414414    tr_lockFree( c->lock );
    415415#else
  • trunk/libtransmission/publish.c

    r3105 r3217  
    3939    assert( *p != NULL );
    4040
    41     tr_list_free( &(*p)->list );
     41    tr_list_free( &(*p)->list, NULL );
    4242    tr_free( *p );
    4343    *p = NULL;
  • trunk/libtransmission/transmission.c

    r3204 r3217  
    347347    assert( i==n );
    348348
    349     tr_list_free( &list );
     349    tr_list_free( &list, NULL );
    350350
    351351    *setmeCount = n;
  • trunk/libtransmission/trevent.c

    r3179 r3217  
    240240
    241241    tr_lockLock( eh->lock );
    242     tr_list_foreach( eh->commands, tr_free );
    243     tr_list_free( &eh->commands );
     242    tr_list_free( &eh->commands, tr_free );
    244243    eh->die = TRUE;
    245244    tr_lockUnlock( eh->lock );
Note: See TracChangeset for help on using the changeset viewer.