mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Do not use an iterator after modifying a collection
Iterators returned by equals_range() are no longer valid when collection is modified. PiperOrigin-RevId: 488728730
This commit is contained in:
committed by
Copybara-Service
parent
beb67fc02a
commit
743e9b4a69
@@ -990,7 +990,7 @@ void BasePcpHandler::OnEndpointFound(
|
||||
NEARBY_LOGS(INFO) << "OnEndpointFound: id=" << endpoint_id << " [enter]";
|
||||
|
||||
auto range = discovered_endpoints_.equal_range(endpoint->endpoint_id);
|
||||
|
||||
bool is_range_empty = range.first == range.second;
|
||||
DiscoveredEndpoint* owned_endpoint = nullptr;
|
||||
for (auto& item = range.first; item != range.second; ++item) {
|
||||
auto& discovered_endpoint = item->second;
|
||||
@@ -1016,7 +1016,7 @@ void BasePcpHandler::OnEndpointFound(
|
||||
|
||||
// Range is empty: this is the first endpoint we discovered so far.
|
||||
// Report this endpoint_id to client.
|
||||
if (range.first == range.second) {
|
||||
if (is_range_empty) {
|
||||
NEARBY_LOGS(INFO) << "Adding new endpoint: endpoint_id=" << endpoint_id;
|
||||
// And, as it's the first time, report it to the client.
|
||||
client->OnEndpointFound(
|
||||
|
||||
Reference in New Issue
Block a user