Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16038] Fix SegFault in delete_contained_entities() when compiled with statistics #3048

Merged
merged 7 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,7 @@ HelloWorldPublisher::~HelloWorldPublisher()
{
if (participant_ != nullptr)
{
if (publisher_ != nullptr)
{
if (writer_ != nullptr)
{
publisher_->delete_datawriter(writer_);
}
participant_->delete_publisher(publisher_);
}
if (topic_ != nullptr)
{
participant_->delete_topic(topic_);
}
participant_->delete_contained_entities();
DomainParticipantFactory::get_instance()->delete_participant(participant_);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/fastdds/domain/DomainParticipantImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class DomainParticipantImpl

DomainId_t get_domain_id() const;

ReturnCode_t delete_contained_entities();
virtual ReturnCode_t delete_contained_entities();
Mario-DL marked this conversation as resolved.
Show resolved Hide resolved

ReturnCode_t assert_liveliness();

Expand Down
13 changes: 13 additions & 0 deletions src/cpp/statistics/fastdds/domain/DomainParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,19 @@ void DomainParticipantImpl::disable()
efd::DomainParticipantImpl::disable();
}

ReturnCode_t DomainParticipantImpl::delete_contained_entities()
{
ReturnCode_t ret = efd::DomainParticipantImpl::delete_contained_entities();

if (ret == ReturnCode_t::RETCODE_OK)
{
builtin_publisher_impl_ = nullptr;
builtin_publisher_ = nullptr;
}

return ret;
}

efd::PublisherImpl* DomainParticipantImpl::create_publisher_impl(
const efd::PublisherQos& qos,
efd::PublisherListener* listener)
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/statistics/fastdds/domain/DomainParticipantImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ class DomainParticipantImpl : public efd::DomainParticipantImpl
static bool is_statistics_topic_name(
const std::string& topic_name) noexcept;

/**
* @brief This override calls the parent method and returns builtin publishers to nullptr
*
* @return RETCODE_OK if successful
*/
ReturnCode_t delete_contained_entities() override;

protected:

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ class DomainParticipantImpl
return false;
}

ReturnCode_t delete_contained_entities()
virtual ReturnCode_t delete_contained_entities()
{
bool can_be_deleted = true;

Expand Down
43 changes: 43 additions & 0 deletions test/unittest/statistics/dds/StatisticsDomainParticipantTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,49 @@ TEST_F(StatisticsDomainParticipantTests, EnableStatisticsDataWriterFailureIncomp
#endif // FASTDDS_STATISTICS
}

/**

* This test checks that a participant is correctly deleted by the factory
* after calling delete_contained_entities() method
* 1. Create a statistics participant, register type
* 2. Create a sample topic
* 3. Perform a delete_contained_entities() in the statistics participant
* 4. Delete the participant
*/
TEST_F(StatisticsDomainParticipantTests, DeleteParticipantAfterDeleteContainedEntitiesFailure)
jparisu marked this conversation as resolved.
Show resolved Hide resolved
{
#ifdef FASTDDS_STATISTICS

eprosima::fastdds::dds::TypeSupport count_type(new EntityCountPubSubType);

// 1. Create DomainParticipant with statistics
eprosima::fastdds::dds::DomainParticipant* participant =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->
create_participant(0, eprosima::fastdds::dds::PARTICIPANT_QOS_DEFAULT);
ASSERT_NE(participant, nullptr);

// Register type
participant->register_type(count_type);

// 2. Create a sample topic
participant->create_topic(HEARTBEAT_COUNT_TOPIC,
count_type->getName(), eprosima::fastdds::dds::TOPIC_QOS_DEFAULT);

DomainParticipant* statistics_participant = DomainParticipant::narrow(participant);
jparisu marked this conversation as resolved.
Show resolved Hide resolved
ASSERT_NE(statistics_participant, nullptr);

EXPECT_EQ(ReturnCode_t::RETCODE_OK, statistics_participant->enable_statistics_datawriter(HEARTBEAT_COUNT_TOPIC,
STATISTICS_DATAWRITER_QOS));

// 3. Perform a delete_contained_entities() in the statistics participant
EXPECT_EQ(statistics_participant->delete_contained_entities(), ReturnCode_t::RETCODE_OK);
rsanchez15 marked this conversation as resolved.
Show resolved Hide resolved

// 4. Delete the participant
EXPECT_EQ(eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->
delete_participant(participant), ReturnCode_t::RETCODE_OK);
#endif // FASTDDS_STATISTICS
}

} // namespace dds
} // namespace statistics
} // namespace fastdds
Expand Down