From 4099ee36b2f4a5fc957d7ccd03ebfc9de56c2206 Mon Sep 17 00:00:00 2001 From: RaulSanchez Date: Thu, 28 Jul 2022 15:38:39 +0200 Subject: [PATCH 1/2] Refs #15312: Disable RTPSParticipantImpl after removing it from RTPSDomain participants list Signed-off-by: RaulSanchez --- src/cpp/rtps/RTPSDomain.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cpp/rtps/RTPSDomain.cpp b/src/cpp/rtps/RTPSDomain.cpp index dc804291115..747bc2f96de 100644 --- a/src/cpp/rtps/RTPSDomain.cpp +++ b/src/cpp/rtps/RTPSDomain.cpp @@ -247,21 +247,24 @@ bool RTPSDomain::removeRTPSParticipant( if (p != nullptr) { assert((p->mp_impl != nullptr) && "This participant has been previously invalidated"); - p->mp_impl->disable(); - std::unique_lock lock(m_mutex); - for (auto it = m_RTPSParticipants.begin(); it != m_RTPSParticipants.end(); ++it) { - if (it->second->getGuid().guidPrefix == p->getGuid().guidPrefix) + std::unique_lock lock(m_mutex); + for (auto it = m_RTPSParticipants.begin(); it != m_RTPSParticipants.end(); ++it) { - RTPSDomain::t_p_RTPSParticipant participant = *it; - m_RTPSParticipants.erase(it); - m_RTPSParticipantIDs.erase(m_RTPSParticipantIDs.find(participant.second->getRTPSParticipantID())); - lock.unlock(); - removeRTPSParticipant_nts(participant); - return true; + if (it->second->getGuid().guidPrefix == p->getGuid().guidPrefix) + { + RTPSDomain::t_p_RTPSParticipant participant = *it; + m_RTPSParticipants.erase(it); + m_RTPSParticipantIDs.erase(m_RTPSParticipantIDs.find(participant.second->getRTPSParticipantID())); + lock.unlock(); + removeRTPSParticipant_nts(participant); + return true; + } } } + + p->mp_impl->disable(); } logError(RTPS_PARTICIPANT, "RTPSParticipant not valid or not recognized"); return false; From f4d17b9f3ba51a684df1a32bf68dd48dc97b2a48 Mon Sep 17 00:00:00 2001 From: RaulSanchez Date: Thu, 28 Jul 2022 16:05:50 +0200 Subject: [PATCH 2/2] Refs #15312: Disable RTPSParticipant in correct place Signed-off-by: RaulSanchez --- src/cpp/rtps/RTPSDomain.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/cpp/rtps/RTPSDomain.cpp b/src/cpp/rtps/RTPSDomain.cpp index 747bc2f96de..f2108080f95 100644 --- a/src/cpp/rtps/RTPSDomain.cpp +++ b/src/cpp/rtps/RTPSDomain.cpp @@ -248,23 +248,19 @@ bool RTPSDomain::removeRTPSParticipant( { assert((p->mp_impl != nullptr) && "This participant has been previously invalidated"); + std::unique_lock lock(m_mutex); + for (auto it = m_RTPSParticipants.begin(); it != m_RTPSParticipants.end(); ++it) { - std::unique_lock lock(m_mutex); - for (auto it = m_RTPSParticipants.begin(); it != m_RTPSParticipants.end(); ++it) + if (it->second->getGuid().guidPrefix == p->getGuid().guidPrefix) { - if (it->second->getGuid().guidPrefix == p->getGuid().guidPrefix) - { - RTPSDomain::t_p_RTPSParticipant participant = *it; - m_RTPSParticipants.erase(it); - m_RTPSParticipantIDs.erase(m_RTPSParticipantIDs.find(participant.second->getRTPSParticipantID())); - lock.unlock(); - removeRTPSParticipant_nts(participant); - return true; - } + RTPSDomain::t_p_RTPSParticipant participant = *it; + m_RTPSParticipants.erase(it); + m_RTPSParticipantIDs.erase(m_RTPSParticipantIDs.find(participant.second->getRTPSParticipantID())); + lock.unlock(); + removeRTPSParticipant_nts(participant); + return true; } } - - p->mp_impl->disable(); } logError(RTPS_PARTICIPANT, "RTPSParticipant not valid or not recognized"); return false; @@ -273,6 +269,7 @@ bool RTPSDomain::removeRTPSParticipant( void RTPSDomain::removeRTPSParticipant_nts( RTPSDomain::t_p_RTPSParticipant& participant) { + participant.second->disable(); // The destructor of RTPSParticipantImpl already deletes the associated RTPSParticipant and sets // its pointer to the RTPSParticipant to nullptr, so there is no need to do it here manually. delete(participant.second);