From 8922990fc7c6e70ae25f6184756c145dfe88c08b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 7 May 2016 14:52:10 -0400 Subject: [PATCH] =?UTF-8?q?fix=20peer=20class=20leak=20in=20torrent=20and?= =?UTF-8?q?=20widen=20peer=5Fclass=5Ft=20to=20allow=20for=20mo=E2=80=A6=20?= =?UTF-8?q?(#707)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix peer class leak in torrent and widen peer_class_t to allow for more instances --- include/libtorrent/peer_class.hpp | 2 +- src/peer_class.cpp | 2 +- src/torrent.cpp | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/peer_class.hpp b/include/libtorrent/peer_class.hpp index a7bc61cc1..a1ca3322a 100644 --- a/include/libtorrent/peer_class.hpp +++ b/include/libtorrent/peer_class.hpp @@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - typedef boost::uint8_t peer_class_t; + typedef boost::uint16_t peer_class_t; struct peer_class_info { diff --git a/src/peer_class.cpp b/src/peer_class.cpp index ce8c810b7..34af2c84e 100644 --- a/src/peer_class.cpp +++ b/src/peer_class.cpp @@ -87,7 +87,7 @@ namespace libtorrent } else { - TORRENT_ASSERT(m_peer_classes.size() < 0x100); + TORRENT_ASSERT(m_peer_classes.size() < 0x10000); ret = peer_class_t(m_peer_classes.size()); m_peer_classes.push_back(boost::shared_ptr()); } diff --git a/src/torrent.cpp b/src/torrent.cpp index f8bbdcb03..e2b4470b6 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -876,6 +876,7 @@ namespace libtorrent // this means that the invariant check that this is called from the // network thread cannot be maintained + TORRENT_ASSERT(m_peer_class == 0); TORRENT_ASSERT(m_abort); TORRENT_ASSERT(m_connections.empty()); if (!m_connections.empty()) @@ -4719,6 +4720,12 @@ namespace libtorrent update_gauge(); stop_announcing(); + if (m_peer_class > 0) + { + m_ses.peer_classes().decref(m_peer_class); + m_peer_class = 0; + } + error_code ec; m_inactivity_timer.cancel(ec);