From c8e8eb6e15e0c2143bb922e3a9652035370b1202 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 12 Jul 2014 19:23:31 +0000 Subject: [PATCH] some asserts in disk_io_thread. fix issue in torrent::initialize --- src/block_cache.cpp | 3 +++ src/disk_io_thread.cpp | 1 + src/torrent.cpp | 8 +++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 06a2ee82e..456f21137 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -332,6 +332,9 @@ void block_cache::cache_hit(cached_piece_entry* p, void* requester, bool volatil // this can be pretty expensive // INVARIANT_CHECK; + TORRENT_ASSERT(p); + TORRENT_ASSERT(p->in_use); + // move the piece into this queue. Whenever we have a cahe // hit, we move the piece into the lru2 queue (i.e. the most // frequently used piece). However, we only do that if the diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 9b3d83a27..51b0c4d38 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -2307,6 +2307,7 @@ namespace libtorrent cached_piece_entry* pe = m_disk_cache.find_piece(j); if (pe) { + TORRENT_ASSERT(pe->in_use); #if TORRENT_USE_ASSERTS pe->piece_log.push_back(piece_log_t(j->action)); #endif diff --git a/src/torrent.cpp b/src/torrent.cpp index 8e537b638..e6fb4dbf4 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1741,11 +1741,13 @@ namespace libtorrent m_connections_initialized = true; // all peer connections have to initialize themselves now that the metadata // is available - for (torrent::peer_iterator i = m_connections.begin(); - i != m_connections.end();) + // copy the peer list since peers may disconnect and invalidate + // m_connections as we initialize them + std::vector peers = m_connections; + for (torrent::peer_iterator i = peers.begin(); + i != peers.end(); ++i) { peer_connection* pc = *i; - ++i; if (pc->is_disconnecting()) continue; pc->on_metadata_impl(); if (pc->is_disconnecting()) continue;