From f9d6c3cdf0ef655efc89e7bfbd465803327229f3 Mon Sep 17 00:00:00 2001 From: Lucia Echevarria Date: Thu, 12 Sep 2024 11:11:25 +0200 Subject: [PATCH 1/2] BugFix: Correct iterator increment after erasing elements in connected_servers_ list Signed-off-by: Lucia Echevarria --- src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp index 79b463466d0..96534dccd93 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp @@ -594,7 +594,7 @@ void PDPClient::removeRemoteEndpoints( eprosima::shared_lock disc_lock(mp_builtin->getDiscoveryMutex()); // Verify if this participant is a server - for (auto it = connected_servers_.begin(); it != connected_servers_.end(); ++it) + for (auto it = connected_servers_.begin(); it != connected_servers_.end();) { if (it->guidPrefix == pdata->m_guid.guidPrefix) { @@ -603,6 +603,10 @@ void PDPClient::removeRemoteEndpoints( is_server = true; mp_sync->restart_timer(); // enable announcement and sync mechanism till this server reappears } + else + { + ++it; + } } } From 71d0c4ae5624f7a6fbeb5c07f5cf00d16f9db07c Mon Sep 17 00:00:00 2001 From: Lucia Echevarria Date: Thu, 12 Sep 2024 12:51:25 +0200 Subject: [PATCH 2/2] Refs #21649. Apply suggested changes Signed-off-by: Lucia Echevarria --- .../rtps/builtin/discovery/participant/PDPClient.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp index 96534dccd93..4075d3cfbf9 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp @@ -594,7 +594,8 @@ void PDPClient::removeRemoteEndpoints( eprosima::shared_lock disc_lock(mp_builtin->getDiscoveryMutex()); // Verify if this participant is a server - for (auto it = connected_servers_.begin(); it != connected_servers_.end();) + auto it = connected_servers_.begin(); + while (it != connected_servers_.end()) { if (it->guidPrefix == pdata->m_guid.guidPrefix) { @@ -602,11 +603,12 @@ void PDPClient::removeRemoteEndpoints( 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; } - else - { - ++it; - } + + ++it; } }