From 71864c18e2432945b669fa6c475ddf6cdaf69ac3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 30 Dec 2008 21:18:30 +0000 Subject: [PATCH] (trunk libT) blockIteratorNew() was overallocating much more memory than it used. --- libtransmission/peer-mgr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index a5ed5d84f..aa1960f11 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -687,7 +687,7 @@ blockIteratorNew( Torrent * t ) struct tr_blockIterator * i = tr_new0( struct tr_blockIterator, 1 ); i->t = t; i->pieces = getPreferredPieces( t, &i->pieceCount ); - i->blocks = tr_new0( tr_block_index_t, t->tor->blockCount ); + i->blocks = tr_new0( tr_block_index_t, t->tor->blockCountInPiece ); return i; } @@ -715,6 +715,8 @@ blockIteratorNext( struct tr_blockIterator * i, tr_block_index_t * setme ) i->blocks[i->blockCount++] = block; } + assert( i->blockCount <= tor->blockCountInPiece ); + if(( found = ( i->blockIndex < i->blockCount ))) *setme = i->blocks[i->blockIndex++];