From c1b3ff72d3d106e322661db3a2702b476eedfe27 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Tue, 15 Sep 2020 22:28:10 +0800 Subject: [PATCH] Fix memory leak because of mock test (#800) * Fix memory leak because of mock test Signed-off-by: Chen Lihui Co-authored-by: Chris Lalancette --- rcl/test/rcl/test_init.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rcl/test/rcl/test_init.cpp b/rcl/test/rcl/test_init.cpp index eb6ffd5c1..dd3c119c0 100644 --- a/rcl/test/rcl/test_init.cpp +++ b/rcl/test/rcl/test_init.cpp @@ -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 @@ -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 @@ -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