diff --git a/src/cpp/statistics/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/statistics/fastdds/domain/DomainParticipantImpl.cpp index 4201348cfa0..5901eba2661 100644 --- a/src/cpp/statistics/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/statistics/fastdds/domain/DomainParticipantImpl.cpp @@ -141,6 +141,8 @@ ReturnCode_t DomainParticipantImpl::enable_statistics_datawriter( auto data_writer = builtin_publisher_impl_->create_datawriter(topic, writer_impl, efd::StatusMask::all()); if (nullptr == data_writer) { + // Remove already created Impl + delete writer_impl; // Remove topic and type delete_topic_and_type(use_topic_name); logError(STATISTICS_DOMAIN_PARTICIPANT, topic_name << " DataWriter creation has failed"); diff --git a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp index b6508cc2ff2..294ad24c05d 100644 --- a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp +++ b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp @@ -96,6 +96,13 @@ class DomainParticipantImpl { eprosima::fastrtps::rtps::RTPSDomain::removeRTPSParticipant(rtps_participant_); } + + if (participant_) + { + participant_->impl_ = nullptr; + delete participant_; + participant_ = nullptr; + } } public: @@ -270,6 +277,7 @@ class DomainParticipantImpl TopicProxy* proxy = new TopicProxy(topic_name, type_name, mask, topic_impl); Topic* topic = proxy->get_topic(); topics_[topic_name] = proxy; + topics_impl_[topic_name] = topic_impl; topic->enable(); return topic; } @@ -302,6 +310,8 @@ class DomainParticipantImpl ReturnCode_t delete_topic( const Topic* topic) { + auto topic_name = topic->get_name(); + if (delete_topic_mock()) { return ReturnCode_t::RETCODE_ERROR; @@ -314,8 +324,9 @@ class DomainParticipantImpl { return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; } + std::lock_guard lock(mtx_topics_); - auto it = topics_.find(topic->get_name()); + auto it = topics_.find(topic_name); if (it != topics_.end()) { if (it->second->is_referenced()) @@ -324,6 +335,11 @@ class DomainParticipantImpl } delete it->second; topics_.erase(it); + + // Destroy also impl, that must exist + delete topics_impl_[topic_name]; + topics_impl_.erase(topic_name); + return ReturnCode_t::RETCODE_OK; } return ReturnCode_t::RETCODE_ERROR; @@ -694,6 +710,7 @@ class DomainParticipantImpl mutable std::mutex mtx_subs_; SubscriberQos default_sub_qos_; std::map topics_; + std::map topics_impl_; mutable std::mutex mtx_topics_; std::map types_; mutable std::mutex mtx_types_; diff --git a/test/mock/dds/Publisher/fastdds/dds/publisher/Publisher.hpp b/test/mock/dds/Publisher/fastdds/dds/publisher/Publisher.hpp index b3c996462fe..cc8f6778f0d 100644 --- a/test/mock/dds/Publisher/fastdds/dds/publisher/Publisher.hpp +++ b/test/mock/dds/Publisher/fastdds/dds/publisher/Publisher.hpp @@ -130,14 +130,14 @@ class Publisher : public Entity } bool get_datawriters( - std::vector& /*writers*/) const + std::vector& writers) const { - return false; + return impl_->get_datawriters(writers); } bool has_datawriters() const { - return false; + return impl_->has_datawriters(); } ReturnCode_t delete_contained_entities()