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>
  • Loading branch information
LuciaEchevarria99 authored Sep 13, 2024
1 parent f910007 commit d4d8e54
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,21 @@ void PDPClient::removeRemoteEndpoints(
eprosima::shared_lock<eprosima::shared_mutex> disc_lock(mp_builtin->getDiscoveryMutex());

// Verify if this participant is a server
for (auto it = connected_servers_.begin(); it != connected_servers_.end(); ++it)
auto it = connected_servers_.begin();
while (it != connected_servers_.end())
{
if (it->guidPrefix == pdata->m_guid.guidPrefix)
{
std::unique_lock<std::recursive_mutex> lock(*getMutex());
it = connected_servers_.erase(it);
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 d4d8e54

Please sign in to comment.