Skip to content

Commit

Permalink
Refs #15831: Fix memory leak in is_active_tests
Browse files Browse the repository at this point in the history
Signed-off-by: jparisu <[email protected]>
  • Loading branch information
jparisu committed Oct 11, 2022
1 parent 11e1fb6 commit 4d6a39d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cpp/StatisticsBackendData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void StatisticsBackendData::stop_monitor(

// The monitor is inactive
// NOTE: for test sake, this is not always set
if (database_->is_entity_present(monitor_id))
if (database_ && database_->is_entity_present(monitor_id))
{
database_->change_entity_status(monitor_id, false);
}
Expand Down
9 changes: 5 additions & 4 deletions test/unittest/StatisticsBackend/IsActiveTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class is_active_tests : public ::testing::Test

void SetUp()
{
db = new DataBaseTest;
db = new DataBaseTest; // This will be deleted inside StatisticsBackendTest unset_database
DatabaseDump dump;
load_file(EMPTY_ENTITIES_DUMP_FILE, dump);
db->load_database(dump);
Expand Down Expand Up @@ -106,6 +106,7 @@ class is_active_tests : public ::testing::Test
delete entity_queue;
delete data_queue;
delete participant_listener;
StatisticsBackendTest::unset_database();
}

std::shared_ptr<Host> host;
Expand All @@ -121,13 +122,13 @@ class is_active_tests : public ::testing::Test
DataBaseTest* db;

// Entity queue, attached to the database
DatabaseEntityQueue* entity_queue;
DatabaseEntityQueue* entity_queue = nullptr;
// Data queue, attached to the database
DatabaseDataQueue* data_queue;
DatabaseDataQueue* data_queue = nullptr;
// Statistics participant_, that is supposed to receive the callbacks
eprosima::fastdds::dds::DomainParticipant statistics_participant;
// Listener under tests. Will receive a pointer to statistics_participant
StatisticsParticipantListener* participant_listener;
StatisticsParticipantListener* participant_listener = nullptr;
};

// Windows dll do not export ParticipantProxyData class members (private APIs)
Expand Down
4 changes: 4 additions & 0 deletions test/unittest/TestUtils/DatabaseUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ class StatisticsBackendTest : public StatisticsBackend
}
}

static void unset_database()
{
details::StatisticsBackendData::get_instance()->database_.reset();
}
};

/**
Expand Down

0 comments on commit 4d6a39d

Please sign in to comment.