Changeset 6850


Ignore:
Timestamp:
Oct 5, 2008, 10:51:18 PM (13 years ago)
Author:
charles
Message:

fix a null pointer dereference

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r6842 r6850  
    13111311                    tr_pex **       setme_pex )
    13121312{
    1313     const Torrent *  t = getExistingTorrent( (tr_peerMgr*)manager,
    1314                                             torrentHash );
    1315     int              i, peerCount;
    1316     const tr_peer ** peers;
    1317     tr_pex *         pex;
    1318     tr_pex *         walk;
     1313    int peerCount = 0;
     1314    const Torrent *  t;
    13191315
    13201316    managerLock( manager );
    13211317
    1322     peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );
    1323     pex = walk = tr_new( tr_pex, peerCount );
    1324 
    1325     for( i = 0; i < peerCount; ++i, ++walk )
    1326     {
    1327         const tr_peer * peer = peers[i];
    1328 
    1329         walk->in_addr = peer->in_addr;
    1330 
    1331         walk->port = peer->port;
    1332 
    1333         walk->flags = 0;
    1334         if( peerPrefersCrypto( peer ) ) walk->flags |=
    1335                 ADDED_F_ENCRYPTION_FLAG;
    1336         if( peer->progress >= 1.0 ) walk->flags |= ADDED_F_SEED_FLAG;
    1337     }
    1338 
    1339     assert( ( walk - pex ) == peerCount );
    1340     qsort( pex, peerCount, sizeof( tr_pex ), tr_pexCompare );
    1341     *setme_pex = pex;
     1318    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
     1319    if( !t )
     1320    {
     1321        *setme_pex = NULL;
     1322    }
     1323    else
     1324    {
     1325        int i;
     1326        const tr_peer ** peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );
     1327        tr_pex * pex = tr_new( tr_pex, peerCount );
     1328        tr_pex * walk = pex;
     1329
     1330        for( i = 0; i < peerCount; ++i, ++walk )
     1331        {
     1332            const tr_peer * peer = peers[i];
     1333            walk->in_addr = peer->in_addr;
     1334            walk->port = peer->port;
     1335            walk->flags = 0;
     1336            if( peerPrefersCrypto( peer ) ) walk->flags |= ADDED_F_ENCRYPTION_FLAG;
     1337            if( peer->progress >= 1.0 ) walk->flags |= ADDED_F_SEED_FLAG;
     1338        }
     1339
     1340        assert( ( walk - pex ) == peerCount );
     1341        qsort( pex, peerCount, sizeof( tr_pex ), tr_pexCompare );
     1342        *setme_pex = pex;
     1343    }
    13421344
    13431345    managerUnlock( manager );
    1344 
    13451346    return peerCount;
    13461347}
Note: See TracChangeset for help on using the changeset viewer.