Skip to content

Commit 7a994bb

Browse files
authored
Fix ASAN errors in tests (#6)
* Fix Owner Ptr leak int test Signed-off-by: jparisu <javierparis@eprosima.com> * Fix SlotThreadPool asan error in test Signed-off-by: jparisu <javierparis@eprosima.com> Signed-off-by: jparisu <javierparis@eprosima.com>
1 parent 1ca3e53 commit 7a994bb

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

cpp_utils/test/unittest/memory/OwnerPtrTest.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ TEST(OwnerPtrTest, owner_ptr_custom_deleter)
143143
{
144144
// Variable to store deleter calls
145145
int deleter_calls = 0;
146+
int* internal_value = new int(42);
146147

147148
// Create Ptr object from int with custom deleter
148149
OwnerPtr<int> ptr(
149-
new int(42),
150+
internal_value,
150151
[&deleter_calls](int*)
151152
{
152153
deleter_calls++;
@@ -163,6 +164,9 @@ TEST(OwnerPtrTest, owner_ptr_custom_deleter)
163164

164165
// As deleter did not destroy object, it should still be accessible
165166
ASSERT_EQ(actual_value_inside, 42);
167+
168+
// Actually remove object as the deleter does not
169+
delete internal_value;
166170
}
167171

168172
/**

cpp_utils/test/unittest/thread_pool/slot_thread_pool_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ TEST(slot_thread_pool_test, pool_one_thread_n_slots)
9999
eprosima::utils::Timer timer;
100100

101101
// Create slot
102-
for (uint32_t i = 0; i < test::N_EXECUTIONS_IN_TEST; ++i)
102+
for (uint32_t i = 1; i <= test::N_EXECUTIONS_IN_TEST; ++i)
103103
{
104104
TaskId task_id(i);
105105
thread_pool.slot(
106106
task_id,
107-
[&waiter, &i]
107+
[&waiter, i]
108108
()
109109
{
110110
test::test_lambda_increase_waiter(waiter, i);
@@ -113,7 +113,7 @@ TEST(slot_thread_pool_test, pool_one_thread_n_slots)
113113
}
114114

115115
// Emit every task 1 time
116-
for (uint32_t i = 0; i < test::N_EXECUTIONS_IN_TEST; ++i)
116+
for (uint32_t i = 1; i <= test::N_EXECUTIONS_IN_TEST; ++i)
117117
{
118118
thread_pool.emit(TaskId(i));
119119
}

0 commit comments

Comments
 (0)