Skip to content

Commit

Permalink
Correct iterator increment after erasing elements in `connected_serve…
Browse files Browse the repository at this point in the history
…rs_list` (#5226)

* BugFix: Correct iterator increment after erasing elements in connected_servers_ list

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Refs #21649. Apply suggested changes

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

---------

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>
(cherry picked from commit d4d8e54)

# Conflicts:
#	src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp
  • Loading branch information
LuciaEchevarria99 authored and mergify[bot] committed Sep 13, 2024
1 parent f5bca04 commit 5a3e0a5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,25 @@ void PDPClient::removeRemoteEndpoints(
eprosima::shared_lock<eprosima::shared_mutex> disc_lock(mp_builtin->getDiscoveryMutex());

// Verify if this participant is a server
<<<<<<< HEAD
for (auto& svr : mp_builtin->m_DiscoveryServers)
=======
auto it = connected_servers_.begin();
while (it != connected_servers_.end())
>>>>>>> d4d8e5489 (Correct iterator increment after erasing elements in `connected_servers_list` (#5226))
{
if (svr.guidPrefix == pdata->m_guid.guidPrefix)
{
std::unique_lock<std::recursive_mutex> lock(*getMutex());
svr.is_connected = false;
is_server = true;
mp_sync->restart_timer(); // enable announcement and sync mechanism till this server reappears

// Avoid incrementing iterator after item removal
continue;
}

++it;
}
}

Expand Down

0 comments on commit 5a3e0a5

Please sign in to comment.