diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 4b81bac09..978d0adbb 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -237,6 +237,9 @@ namespace libtorrent , boost::bind(&boost::intrusive_ptr::get, _1) == p) != m_connections.end(); } + // this is set while the session is building the + // torrent status update message + bool m_posting_torrent_updates; #endif void main_thread(); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 4bdc908ef..7080bb3f6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -672,6 +672,10 @@ namespace aux { , m_network_thread(0) #endif { +#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS + m_posting_torrent_updates = false; +#endif + memset(m_redundant_bytes, 0, sizeof(m_redundant_bytes)); m_udp_socket.set_rate_limit(m_settings.dht_upload_rate_limit); @@ -4792,6 +4796,10 @@ namespace aux { std::auto_ptr alert(new state_update_alert()); alert->status.reserve(m_state_updates.size()); +#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS + m_posting_torrent_updates = true; +#endif + for (std::vector >::iterator i = m_state_updates.begin() , end(m_state_updates.end()); i != end; ++i) { @@ -4803,6 +4811,10 @@ namespace aux { } m_state_updates.clear(); +#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS + m_posting_torrent_updates = false; +#endif + m_alerts.post_alert_ptr(alert.release()); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 7ddfb9fd3..070b8d005 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2923,7 +2923,7 @@ namespace libtorrent TORRENT_ASSERT(st.total_wanted >= st.total_wanted_done); // subtract padding files - if (m_padding > 0) + if (m_padding > 0 && accurate) { file_storage const& files = m_torrent_file->files(); int fileno = 0; @@ -8398,6 +8398,10 @@ namespace libtorrent // this should probably be moved to torrent::start() TORRENT_ASSERT(shared_from_this()); + // we can't call state_updated() while the session + // is building the status update alert + TORRENT_ASSERT(!m_ses.m_posting_torrent_updates); + // we're either not subscribing to this torrent, or // it has already been updated this round, no need to // add it to the list twice