Skip to content

Commit

Permalink
Fix a memory leak in test_rcl_lifecycle. (#1173)
Browse files Browse the repository at this point in the history
This one came about probably as a result of a bad merge.
But essentially we were forcing the srv_change_state
com_interface to be nullptr, but forgetting to save off
the old pointer early enough.  Thus, we could never restore
the old one before we went to "fini", and the memory would
be leaked.  Fix this by remembering the impl pointer earlier.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
  • Loading branch information
clalancette authored Jul 26, 2024
1 parent 5193dc6 commit 6df1195
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rcl_lifecycle/test/test_rcl_lifecycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ TEST(TestRclLifecycle, state_machine) {
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_lifecycle_state_machine_is_initialized(&state_machine));
rcutils_reset_error();

void * temp_function = state_machine.com_interface.srv_change_state.impl;
state_machine.com_interface.srv_change_state.impl = nullptr;
// get_state service is valid, but not change_state service
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_lifecycle_state_machine_is_initialized(&state_machine));
Expand All @@ -357,10 +358,9 @@ TEST(TestRclLifecycle, state_machine) {
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_lifecycle_state_machine_is_initialized(&state_machine));

// get_state service is valid, but not change_state service
void * temp_function = state_machine.com_interface.srv_change_state.impl;
state_machine.com_interface.srv_change_state.impl = nullptr;
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_lifecycle_state_machine_is_initialized(&state_machine));
rcutils_reset_error();

state_machine.com_interface.srv_change_state.impl =
reinterpret_cast<rcl_service_impl_t *>(temp_function);

Expand Down

0 comments on commit 6df1195

Please sign in to comment.