From 93cb1c89adca05ea9edc4852ab78a1b7c81d6708 Mon Sep 17 00:00:00 2001 From: Eric Petit Date: Sat, 20 Jan 2007 04:29:33 +0000 Subject: [PATCH] Make sure we don't malloc(0), and save peers in the cache file even if we haven't successfully connected to them yet --- libtransmission/peer.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libtransmission/peer.c b/libtransmission/peer.c index cc9ce3a6b..b3172b972 100644 --- a/libtransmission/peer.c +++ b/libtransmission/peer.c @@ -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 count = 0; - uint8_t * buf = malloc( 6 * tor->peerCount ); + uint8_t * buf; tr_peer_t * peer; int i; + if( tor->peerCount < 1 ) + { + *_buf = NULL; + return 0; + } + + buf = malloc( 6 * tor->peerCount ); for( i = 0; i < tor->peerCount; i++ ) { peer = tor->peers[i]; - /* Skip peers for which the connection isn't established, - * and peers that came from incoming connections */ - if( peer->status < PEER_STATUS_CONNECTED ) - continue; + /* Skip peers that came from incoming connections */ if( peer->incoming ) continue; @@ -654,13 +658,9 @@ int tr_peerGetConnectable( tr_torrent_t * tor, uint8_t ** _buf ) if( count < 1 ) { - free( buf ); - *_buf = NULL; - } - else - { - *_buf = buf; + free( buf ); buf = NULL; } + *_buf = buf; return count * 6; }