From 587792ec5b897d92b10d6a18bea472bb6428d898 Mon Sep 17 00:00:00 2001 From: LuciaEchevarria99 <110391668+LuciaEchevarria99@users.noreply.github.com> Date: Fri, 13 Sep 2024 07:46:26 +0200 Subject: [PATCH] Correct iterator increment after erasing elements in `connected_servers_list` (#5226) * BugFix: Correct iterator increment after erasing elements in connected_servers_ list Signed-off-by: Lucia Echevarria * Refs #21649. Apply suggested changes Signed-off-by: Lucia Echevarria --------- Signed-off-by: Lucia Echevarria (cherry picked from commit d4d8e5489b684f49ae574e2bb40454461f8ab6db) # Conflicts: # src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp --- .../rtps/builtin/discovery/participant/PDPClient.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp index 8e33bfa1d81..9d974458f0e 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp @@ -599,7 +599,12 @@ void PDPClient::removeRemoteEndpoints( eprosima::shared_lock 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) { @@ -607,7 +612,12 @@ void PDPClient::removeRemoteEndpoints( 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; } }