From 5fa8995b85e969d1c47182259d8d8469475061df Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Sat, 28 Nov 2026 15:36:19 -0600 Subject: [PATCH 1/2] Release wait sets and clients that the tests leak test_graph_listener, and the is_ready tests of the action client and generic client, initialize an rcl wait set by hand and never finalize it. construction_and_destruction_rcl_errors replaces rcl_action_client_fini() with a function that only returns an error, so the client is never finalized. Finalize the wait sets, and call the real rcl_action_client_fini() before injecting the error. Found with LeakSanitizer. Signed-off-by: Michael Carroll --- rclcpp/test/rclcpp/test_graph_listener.cpp | 12 ++++++++++-- rclcpp_action/test/test_client.cpp | 3 ++- rclcpp_action/test/test_generic_client.cpp | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/rclcpp/test/rclcpp/test_graph_listener.cpp b/rclcpp/test/rclcpp/test_graph_listener.cpp index 2dd8050545..92d0019f86 100644 --- a/rclcpp/test/rclcpp/test_graph_listener.cpp +++ b/rclcpp/test/rclcpp/test_graph_listener.cpp @@ -162,6 +162,8 @@ TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_set_clear) { RCLCPP_EXPECT_THROW_EQ( graph_listener_test->run_protected(), std::runtime_error("failed to clear wait set: error not set")); + // the wait set was initialized by hand, release it + graph_listener_test->mock_cleanup_wait_set(); } TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_set_add_guard_condition) { @@ -174,6 +176,8 @@ TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_set_add_guard_condi RCLCPP_EXPECT_THROW_EQ( graph_listener_test->run_protected(), std::runtime_error("failed to add guard condition to wait set: error not set")); + // the wait set was initialized by hand, release it + graph_listener_test->mock_cleanup_wait_set(); } TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_error) { @@ -186,6 +190,8 @@ TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_error) { RCLCPP_EXPECT_THROW_EQ( graph_listener_test->run_protected(), std::runtime_error("failed to wait on wait set: error not set")); + // the wait set was initialized by hand, release it + graph_listener_test->mock_cleanup_wait_set(); } TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_timeout) { @@ -198,6 +204,8 @@ TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_timeout) { RCLCPP_EXPECT_THROW_EQ( graph_listener_test->run_protected(), std::runtime_error("rcl_wait unexpectedly timed out")); + // the wait set was initialized by hand, release it + graph_listener_test->mock_cleanup_wait_set(); } /* Add/Remove node usage */ @@ -272,14 +280,14 @@ TEST_F(TestGraphListener, test_graph_listener_shutdown_wait_fini_error_throw) { auto graph_listener_test = std::make_shared(global_context); - graph_listener()->start_if_not_started(); + graph_listener_test->start_if_not_started(); { auto mock_wait_set_fini = mocking_utils::patch_and_return( "lib:rclcpp", rcl_wait_set_fini, RCL_RET_ERROR); RCLCPP_EXPECT_THROW_EQ( - graph_listener()->shutdown(), + graph_listener_test->shutdown(), std::runtime_error("failed to finalize wait set: error not set")); } diff --git a/rclcpp_action/test/test_client.cpp b/rclcpp_action/test/test_client.cpp index c461d1eeed..627fd6108e 100644 --- a/rclcpp_action/test/test_client.cpp +++ b/rclcpp_action/test/test_client.cpp @@ -391,7 +391,7 @@ TEST_F(TestClient, construction_and_destruction_callback_group) TEST_F(TestClient, construction_and_destruction_rcl_errors) { { - auto mock = mocking_utils::patch_and_return( + auto mock = mocking_utils::inject_on_return( "lib:rclcpp_action", rcl_action_client_fini, RCL_RET_ERROR); // It just logs an error message and continues EXPECT_NO_THROW( @@ -577,6 +577,7 @@ TEST_F(TestClient, is_ready) { "lib:rclcpp_action", rcl_action_client_wait_set_get_entities_ready, RCL_RET_ERROR); EXPECT_THROW(action_client->is_ready(wait_set), rclcpp::exceptions::RCLError); } + EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set)); client_node.reset(); // Drop node before action client } diff --git a/rclcpp_action/test/test_generic_client.cpp b/rclcpp_action/test/test_generic_client.cpp index 0bca9acd0b..fc0a61a1bd 100644 --- a/rclcpp_action/test/test_generic_client.cpp +++ b/rclcpp_action/test/test_generic_client.cpp @@ -450,6 +450,7 @@ TEST_F(TestGenericClient, is_ready) { "lib:rclcpp_action", rcl_action_client_wait_set_get_entities_ready, RCL_RET_ERROR); EXPECT_THROW(action_generic_client->is_ready(wait_set), rclcpp::exceptions::RCLError); } + EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set)); client_node.reset(); // Drop node before action client } From 7551fc9a27a74ca3a87c2fc1ff1c8c423c1e925e Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 30 Nov 2026 07:34:24 -0600 Subject: [PATCH 2/2] Keep patch_and_return for rcl_action_client_fini; inject_on_return crashes on RHEL Signed-off-by: Michael Carroll --- rclcpp_action/test/test_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rclcpp_action/test/test_client.cpp b/rclcpp_action/test/test_client.cpp index 627fd6108e..54b9426b31 100644 --- a/rclcpp_action/test/test_client.cpp +++ b/rclcpp_action/test/test_client.cpp @@ -391,7 +391,7 @@ TEST_F(TestClient, construction_and_destruction_callback_group) TEST_F(TestClient, construction_and_destruction_rcl_errors) { { - auto mock = mocking_utils::inject_on_return( + auto mock = mocking_utils::patch_and_return( "lib:rclcpp_action", rcl_action_client_fini, RCL_RET_ERROR); // It just logs an error message and continues EXPECT_NO_THROW(