From c91613a49f07792a0c2def0bc2b843fcea92cd38 Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Thu, 15 Feb 2024 12:14:12 +0800 Subject: [PATCH] fix: use `std::unordered_map` as a stand-in for `small::map` --- libtransmission/peer-mgr.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libtransmission/peer-mgr.cc b/libtransmission/peer-mgr.cc index 1b611bb97..9b91d3f2b 100644 --- a/libtransmission/peer-mgr.cc +++ b/libtransmission/peer-mgr.cc @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -284,7 +283,8 @@ class tr_swarm { public: using Peers = std::vector; - using Pool = small::map>; + // FIXME(tearfur) replace std::unordered_map with small::map after their bugs are fixed + using Pool = std::unordered_map>; class WishlistMediator final : public Wishlist::Mediator { @@ -378,7 +378,11 @@ public: void remove_inactive_peer_info() noexcept { auto const now = tr_time(); - for (auto iter = std::begin(connectable_pool), end = std::end(connectable_pool); iter != end;) + + // N.B. Unlike `std::map`, erasing elements in `small::map` seems to invalidate + // iterators other than the one being erased. So make sure `std::end()` is called + // every iteration + for (auto iter = std::begin(connectable_pool); iter != std::end(connectable_pool);) { auto const& [socket_address, peer_info] = *iter; if (peer_info->is_inactive(now))