From 698b2969884a8007636a16bf993bf9a64f15d2b5 Mon Sep 17 00:00:00 2001 From: Eduardo Ponz Segrelles Date: Fri, 12 Nov 2021 07:20:02 +0100 Subject: [PATCH] Disable DataReader on destruction (#2313) * Refs #12870: Disable datareader on destruction Signed-off-by: Eduardo Ponz Segrelles * Refs #12870: Protect RTPSReader::setListener Signed-off-by: Eduardo Ponz Segrelles (cherry picked from commit d4de4a1bda5b831e47acdd85d5a22f1e8c7db84c) --- src/cpp/fastdds/subscriber/DataReaderImpl.cpp | 2 ++ src/cpp/fastdds/subscriber/SubscriberImpl.cpp | 1 - src/cpp/rtps/reader/RTPSReader.cpp | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp index c260f8b5cc9..dd2c02f5736 100644 --- a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp +++ b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp @@ -285,6 +285,8 @@ void DataReaderImpl::disable() DataReaderImpl::~DataReaderImpl() { + // Disable the datareader to prevent receiving data in the middle of deleting it + disable(); delete lifespan_timer_; delete deadline_timer_; diff --git a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp index 5a1063342eb..fdc41441008 100644 --- a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp +++ b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp @@ -314,7 +314,6 @@ ReturnCode_t SubscriberImpl::delete_datareader( return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; } - reader_impl->set_listener(nullptr); it->second.erase(dr_it); if (it->second.empty()) { diff --git a/src/cpp/rtps/reader/RTPSReader.cpp b/src/cpp/rtps/reader/RTPSReader.cpp index a2dfb0e2189..11860585636 100644 --- a/src/cpp/rtps/reader/RTPSReader.cpp +++ b/src/cpp/rtps/reader/RTPSReader.cpp @@ -208,6 +208,7 @@ ReaderListener* RTPSReader::getListener() const bool RTPSReader::setListener( ReaderListener* target) { + std::lock_guard guard(mp_mutex); mp_listener = target; return true; }