1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

Make sure we don't malloc(0), and save peers in the cache file even if we haven't successfully connected to them yet

This commit is contained in:
Eric Petit 2007-01-20 04:29:33 +00:00
parent 0282ec5722
commit 93cb1c89ad

View file

@ -632,18 +632,22 @@ void tr_peerBlame( tr_torrent_t * tor, tr_peer_t * peer,
int tr_peerGetConnectable( tr_torrent_t * tor, uint8_t ** _buf ) int tr_peerGetConnectable( tr_torrent_t * tor, uint8_t ** _buf )
{ {
int count = 0; int count = 0;
uint8_t * buf = malloc( 6 * tor->peerCount ); uint8_t * buf;
tr_peer_t * peer; tr_peer_t * peer;
int i; int i;
if( tor->peerCount < 1 )
{
*_buf = NULL;
return 0;
}
buf = malloc( 6 * tor->peerCount );
for( i = 0; i < tor->peerCount; i++ ) for( i = 0; i < tor->peerCount; i++ )
{ {
peer = tor->peers[i]; peer = tor->peers[i];
/* Skip peers for which the connection isn't established, /* Skip peers that came from incoming connections */
* and peers that came from incoming connections */
if( peer->status < PEER_STATUS_CONNECTED )
continue;
if( peer->incoming ) if( peer->incoming )
continue; continue;
@ -654,13 +658,9 @@ int tr_peerGetConnectable( tr_torrent_t * tor, uint8_t ** _buf )
if( count < 1 ) if( count < 1 )
{ {
free( buf ); free( buf ); buf = NULL;
*_buf = NULL;
} }
else
{
*_buf = buf; *_buf = buf;
}
return count * 6; return count * 6;
} }