From 0c507637db9abbf405158f483d76c86a62cd622d Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Mon, 8 Jul 2013 17:46:12 +0000 Subject: [PATCH] in peer-mgr.c's tr_peerMgrGetDesiredAvailable(), confirm we have a swarm pointer before using it. Probable fix for bug #5407 --- libtransmission/peer-mgr.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 0dc101a81..5a049d04e 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -2610,16 +2610,22 @@ tr_peerMgrGetDesiredAvailable (const tr_torrent * tor) size_t i; size_t n; uint64_t desiredAvailable; - const tr_swarm * s = tor->swarm; + const tr_swarm * s; + + assert (tr_isTorrent (tor)); /* common shortcuts... */ - if (tr_torrentIsSeed (s->tor)) + if (tr_torrentIsSeed (tor)) return 0; if (!tr_torrentHasMetadata (tor)) return 0; + s = tor->swarm; + if (s == NULL) + return 0; + n = tr_ptrArraySize (&s->peers); if (n == 0) { @@ -2641,7 +2647,7 @@ tr_peerMgrGetDesiredAvailable (const tr_torrent * tor) desiredAvailable = 0; for (i=0, n=MIN (tor->info.pieceCount, s->pieceReplicationSize); iinfo.pieces[i].dnd && (s->pieceReplication[i] > 0)) - desiredAvailable += tr_cpMissingBytesInPiece (&s->tor->completion, i); + desiredAvailable += tr_cpMissingBytesInPiece (&tor->completion, i); assert (desiredAvailable <= tor->info.totalSize); return desiredAvailable; @@ -3377,7 +3383,7 @@ struct peer_liveliness void * clientData; time_t pieceDataTime; time_t time; - int speed; + unsigned int speed; bool doPurge; }; -- 2.40.0