Skip to content

Commit

Permalink
Fix memory leak because of mock test (#800)
Browse files Browse the repository at this point in the history
* Fix memory leak because of mock test

Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
  • Loading branch information
Chen Lihui and clalancette authored Sep 15, 2020
1 parent f3396a2 commit c1b3ff7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rcl/test/rcl/test_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_mocked_rcl_init_optio
auto mock = mocking_utils::inject_on_return("lib:rcl", rmw_init_options_fini, RMW_RET_ERROR);
EXPECT_EQ(RCL_RET_ERROR, rcl_init_options_fini(&init_options));
rcl_reset_error();
auto mock_ok = mocking_utils::inject_on_return("lib:rcl", rmw_init_options_fini, RMW_RET_OK);
EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options));
}

// Mock rcl_init_options_copy to fail
Expand All @@ -559,6 +561,8 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_copy_mocked_
auto mock = mocking_utils::inject_on_return("lib:rcl", rmw_init_options_fini, RMW_RET_ERROR);
EXPECT_EQ(RCL_RET_ERROR, rcl_init_options_copy(&init_options, &init_options_dst));
rcl_reset_error();
auto mock_ok = mocking_utils::inject_on_return("lib:rcl", rmw_init_options_fini, RMW_RET_OK);
EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options_dst));
}

// Mock rcl_init_options_copy to fail
Expand All @@ -578,6 +582,8 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_copy
RCL_RET_INVALID_ARGUMENT,
rcl_init_options_fini(&init_options_dst)) << rcl_get_error_string().str;
rcl_reset_error();
auto mock_ok = mocking_utils::patch_and_return("lib:rcl", rmw_init_options_fini, RMW_RET_OK);
EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options_dst)) << rcl_get_error_string().str;
});

// rmw_init_options_copy error is logged
Expand Down

0 comments on commit c1b3ff7

Please sign in to comment.