Skip to content

Commit 064a021

Browse files
authored
Change to using unique_ptrs for DummyExecutor. (ros2#1517)
* Change to using unique_ptrs for DummyExecutor. clang static analysis suggested that there was a possible memory leak here, and it is right. The test is expecting to throw during the constructor, in which case the memory would be automatically freed. However, if the test did *not* throw for some reason, we would leak the memory. Switch to using a unique_ptr here which will free the memory in all cases at the end of the scope. Signed-off-by: Chris Lalancette <[email protected]>
1 parent 5cb2274 commit 064a021

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

rclcpp/test/rclcpp/test_executor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ TEST_F(TestExecutor, constructor_bad_guard_condition_init) {
122122
auto mock = mocking_utils::patch_and_return(
123123
"lib:rclcpp", rcl_guard_condition_init, RCL_RET_ERROR);
124124
EXPECT_THROW(
125-
new DummyExecutor(),
125+
static_cast<void>(std::make_unique<DummyExecutor>()),
126126
rclcpp::exceptions::RCLError);
127127
}
128128

129129
TEST_F(TestExecutor, constructor_bad_wait_set_init) {
130130
auto mock = mocking_utils::patch_and_return("lib:rclcpp", rcl_wait_set_init, RCL_RET_ERROR);
131131
RCLCPP_EXPECT_THROW_EQ(
132-
new DummyExecutor(),
132+
static_cast<void>(std::make_unique<DummyExecutor>()),
133133
std::runtime_error("Failed to create wait set in Executor constructor: error not set"));
134134
}
135135

0 commit comments

Comments
 (0)