Skip to content

Commit

Permalink
Fix memory leak on serialized message in test_publisher/subscription.…
Browse files Browse the repository at this point in the history
…cpp (#801)

* Fix memory leak on serialized message in test_publisher/subscription.cpp

Signed-off-by: Barry Xu <[email protected]>
  • Loading branch information
Barry-Xu-2018 authored Sep 17, 2020
1 parent c1b3ff7 commit 8bcada7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rcl/test/rcl/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ TEST_F(
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
test_msgs__msg__Strings__fini(&msg);
ASSERT_EQ(
RMW_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));
Expand Down
10 changes: 10 additions & 0 deletions rcl/test/rcl/test_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ 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);
ASSERT_EQ(
RMW_RET_OK,
rmw_serialized_message_fini(&serialized_msg)) << rcl_get_error_string().str;
});
rcl_reset_error();

Expand All @@ -595,6 +600,11 @@ 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);
ASSERT_EQ(
RMW_RET_OK,
rmw_serialized_message_fini(&serialized_msg_rcv)) << rcl_get_error_string().str;
}
}

Expand Down

0 comments on commit 8bcada7

Please sign in to comment.