Skip to content

Commit 4d6a39d

Browse files
author
jparisu
committed
Refs #15831: Fix memory leak in is_active_tests
Signed-off-by: jparisu <[email protected]>
1 parent 11e1fb6 commit 4d6a39d

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/cpp/StatisticsBackendData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void StatisticsBackendData::stop_monitor(
367367

368368
// The monitor is inactive
369369
// NOTE: for test sake, this is not always set
370-
if (database_->is_entity_present(monitor_id))
370+
if (database_ && database_->is_entity_present(monitor_id))
371371
{
372372
database_->change_entity_status(monitor_id, false);
373373
}

test/unittest/StatisticsBackend/IsActiveTests.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class is_active_tests : public ::testing::Test
3636

3737
void SetUp()
3838
{
39-
db = new DataBaseTest;
39+
db = new DataBaseTest; // This will be deleted inside StatisticsBackendTest unset_database
4040
DatabaseDump dump;
4141
load_file(EMPTY_ENTITIES_DUMP_FILE, dump);
4242
db->load_database(dump);
@@ -106,6 +106,7 @@ class is_active_tests : public ::testing::Test
106106
delete entity_queue;
107107
delete data_queue;
108108
delete participant_listener;
109+
StatisticsBackendTest::unset_database();
109110
}
110111

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

123124
// Entity queue, attached to the database
124-
DatabaseEntityQueue* entity_queue;
125+
DatabaseEntityQueue* entity_queue = nullptr;
125126
// Data queue, attached to the database
126-
DatabaseDataQueue* data_queue;
127+
DatabaseDataQueue* data_queue = nullptr;
127128
// Statistics participant_, that is supposed to receive the callbacks
128129
eprosima::fastdds::dds::DomainParticipant statistics_participant;
129130
// Listener under tests. Will receive a pointer to statistics_participant
130-
StatisticsParticipantListener* participant_listener;
131+
StatisticsParticipantListener* participant_listener = nullptr;
131132
};
132133

133134
// Windows dll do not export ParticipantProxyData class members (private APIs)

test/unittest/TestUtils/DatabaseUtils.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ class StatisticsBackendTest : public StatisticsBackend
636636
}
637637
}
638638

639+
static void unset_database()
640+
{
641+
details::StatisticsBackendData::get_instance()->database_.reset();
642+
}
639643
};
640644

641645
/**

0 commit comments

Comments
 (0)