diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 438604deb..eb2b5890d 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -452,7 +452,7 @@ namespace libtorrent void get_full_peer_list(std::vector& v) const; void get_peer_info(std::vector& v); - void get_download_queue(std::vector& queue); + void get_download_queue(std::vector* queue); void refresh_explicit_cache(int cache_size); diff --git a/src/torrent.cpp b/src/torrent.cpp index b239907cd..21c6b1644 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5350,10 +5350,10 @@ ctx->set_verify_callback(verify_function, ec); } } - void torrent::get_download_queue(std::vector& queue) + void torrent::get_download_queue(std::vector* queue) { TORRENT_ASSERT(m_ses.is_network_thread()); - queue.clear(); + queue->clear(); std::vector& blk = m_ses.m_block_info_storage; blk.clear(); @@ -5364,6 +5364,10 @@ ctx->set_verify_callback(verify_function, ec); const int blocks_per_piece = m_picker->blocks_in_piece(0); blk.resize(q.size() * blocks_per_piece); + // for some weird reason valgrind claims these are uninitialized + // unless it's zeroed out here (block_info has a construct that's + // supposed to initialize it) + memset(&blk[0], 0, sizeof(blk[0]) * blk.size()); int counter = 0; for (std::vector::const_iterator i @@ -5375,6 +5379,7 @@ ctx->set_verify_callback(verify_function, ec); pi.finished = (int)i->finished; pi.writing = (int)i->writing; pi.requested = (int)i->requested; + TORRENT_ASSERT(counter * blocks_per_piece + pi.blocks_in_piece <= int(blk.size())); pi.blocks = &blk[counter * blocks_per_piece]; int piece_size = int(torrent_file().piece_size(i->index)); for (int j = 0; j < pi.blocks_in_piece; ++j) @@ -5425,7 +5430,7 @@ ctx->set_verify_callback(verify_function, ec); pi.blocks[j].num_peers = i->info[j].num_peers; } pi.piece_index = i->index; - queue.push_back(pi); + queue->push_back(pi); } } diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 6eeb659ae..ffc1f2d7a 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -877,7 +877,7 @@ namespace libtorrent void torrent_handle::get_download_queue(std::vector& queue) const { INVARIANT_CHECK; - TORRENT_SYNC_CALL1(get_download_queue, boost::ref(queue)); + TORRENT_SYNC_CALL1(get_download_queue, &queue); } void torrent_handle::set_piece_deadline(int index, int deadline, int flags) const