From 1828e2638744e3106ebfe54782eccfa873310166 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Mon, 7 Sep 2020 17:34:29 +0800 Subject: [PATCH 1/3] Fix memory leak on serialized message in test_publisher/subscription.cpp Signed-off-by: Barry Xu --- rcl/test/rcl/test_publisher.cpp | 3 +++ rcl/test/rcl/test_subscription.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index c536f9242..fc2d25b32 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -603,6 +603,9 @@ TEST_F( OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( { test_msgs__msg__Strings__fini(&msg); + ASSERT_EQ( + RCUTILS_RET_OK, + rmw_serialized_message_fini(&serialized_msg)) << rcl_get_error_string().str; }); ASSERT_TRUE(rosidl_runtime_c__String__assign(&msg.string_value, test_string)); diff --git a/rcl/test/rcl/test_subscription.cpp b/rcl/test/rcl/test_subscription.cpp index 471a3110a..537c347f2 100644 --- a/rcl/test/rcl/test_subscription.cpp +++ b/rcl/test/rcl/test_subscription.cpp @@ -571,6 +571,10 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription { ret = rcl_subscription_fini(&subscription, this->node_ptr); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + + test_msgs__msg__Strings__fini(&msg); + ret = rmw_serialized_message_fini(&serialized_msg); + ASSERT_EQ(RCUTILS_RET_OK, ret) << rcl_get_error_string().str; }); rcl_reset_error(); @@ -595,6 +599,10 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription ASSERT_EQ(RMW_RET_OK, ret); ASSERT_EQ( std::string(test_string), std::string(msg_rcv.string_value.data, msg_rcv.string_value.size)); + + test_msgs__msg__Strings__fini(&msg_rcv); + ret = rmw_serialized_message_fini(&serialized_msg_rcv); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; } } From 3f4af5bab293c5024f06134263bcdd0bf195282b Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Wed, 16 Sep 2020 09:22:28 +0800 Subject: [PATCH 2/3] Change RCUTILS_RET_OK to RMW_RET_OK Signed-off-by: Barry Xu --- rcl/test/rcl/test_publisher.cpp | 2 +- rcl/test/rcl/test_subscription.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index fc2d25b32..3fcbe0227 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -604,7 +604,7 @@ TEST_F( { test_msgs__msg__Strings__fini(&msg); ASSERT_EQ( - RCUTILS_RET_OK, + RMW_RET_OK, rmw_serialized_message_fini(&serialized_msg)) << rcl_get_error_string().str; }); diff --git a/rcl/test/rcl/test_subscription.cpp b/rcl/test/rcl/test_subscription.cpp index 537c347f2..751bb94a1 100644 --- a/rcl/test/rcl/test_subscription.cpp +++ b/rcl/test/rcl/test_subscription.cpp @@ -574,7 +574,7 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription test_msgs__msg__Strings__fini(&msg); ret = rmw_serialized_message_fini(&serialized_msg); - ASSERT_EQ(RCUTILS_RET_OK, ret) << rcl_get_error_string().str; + ASSERT_EQ(RMW_RET_OK, ret) << rcl_get_error_string().str; }); rcl_reset_error(); @@ -602,7 +602,7 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription test_msgs__msg__Strings__fini(&msg_rcv); ret = rmw_serialized_message_fini(&serialized_msg_rcv); - ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + ASSERT_EQ(RMW_RET_OK, ret) << rcl_get_error_string().str; } } From 18ab60b78aa6b47457518b1a6e62fa2d01430a34 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Thu, 17 Sep 2020 09:52:59 +0800 Subject: [PATCH 3/3] Combine 2 lines codes Signed-off-by: Barry Xu --- rcl/test/rcl/test_subscription.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rcl/test/rcl/test_subscription.cpp b/rcl/test/rcl/test_subscription.cpp index 751bb94a1..2d0e4b635 100644 --- a/rcl/test/rcl/test_subscription.cpp +++ b/rcl/test/rcl/test_subscription.cpp @@ -573,8 +573,9 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; test_msgs__msg__Strings__fini(&msg); - ret = rmw_serialized_message_fini(&serialized_msg); - ASSERT_EQ(RMW_RET_OK, ret) << rcl_get_error_string().str; + ASSERT_EQ( + RMW_RET_OK, + rmw_serialized_message_fini(&serialized_msg)) << rcl_get_error_string().str; }); rcl_reset_error(); @@ -601,8 +602,9 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription std::string(test_string), std::string(msg_rcv.string_value.data, msg_rcv.string_value.size)); test_msgs__msg__Strings__fini(&msg_rcv); - ret = rmw_serialized_message_fini(&serialized_msg_rcv); - ASSERT_EQ(RMW_RET_OK, ret) << rcl_get_error_string().str; + ASSERT_EQ( + RMW_RET_OK, + rmw_serialized_message_fini(&serialized_msg_rcv)) << rcl_get_error_string().str; } }