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; }