Skip to content

Commit

Permalink
calling fini functions to avoid memory leak (ros2#791)
Browse files Browse the repository at this point in the history
* Fix test memory leaks

1.  calling rcutils_string_map_fini to avoid memory leak
2.  Fix memory leak that not to call rcutils_string_array_fini for enclaves
3.  Fix that not to rcutils_string_array_fini for node_names_2 and node_namespaces_2
4.  Fix that not to rcl_log_levels_fini for copied_log_levels
5.  Fix that not to call rmw_security_options_fini for options
6.  Call test_msgs__srv__BasicTypes_Request__fini for service_request in the end

Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
  • Loading branch information
Chen Lihui authored Sep 8, 2020
1 parent e88b63b commit 78ed316
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rcl/test/rcl/test_expand_topic_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ TEST(test_expand_topic_name, internal_error) {
EXPECT_TRUE(rcl_error_is_set());
rcl_reset_error();
}

ret = rcutils_string_map_fini(&subs);
ASSERT_EQ(RCL_RET_OK, ret);
}

TEST(test_expand_topic_name, various_valid_topics) {
Expand Down
3 changes: 3 additions & 0 deletions rcl/test/rcl/test_get_node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ TEST_F(
ret = rcutils_string_array_fini(&node_namespaces);
ASSERT_EQ(RCUTILS_RET_OK, ret);

ret = rcutils_string_array_fini(&enclaves);
ASSERT_EQ(RCUTILS_RET_OK, ret);

ret = rcl_node_fini(&node1);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;

Expand Down
4 changes: 4 additions & 0 deletions rcl/test/rcl/test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,10 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_bad_get_node_names)
EXPECT_EQ(RCUTILS_RET_OK, ret);
ret = rcutils_string_array_fini(&node_namespaces);
EXPECT_EQ(RCUTILS_RET_OK, ret);
ret = rcutils_string_array_fini(&node_names_2);
EXPECT_EQ(RCUTILS_RET_OK, ret);
ret = rcutils_string_array_fini(&node_namespaces_2);
EXPECT_EQ(RCUTILS_RET_OK, ret);
ret = rcutils_string_array_fini(&node_enclaves);
EXPECT_EQ(RCUTILS_RET_OK, ret);
});
Expand Down
4 changes: 4 additions & 0 deletions rcl/test/rcl/test_log_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ TEST(TestLogLevel, logger_log_level_copy) {
// Expected usage
rcl_log_levels_t copied_log_levels = rcl_get_zero_initialized_log_levels();
EXPECT_EQ(RCL_RET_OK, rcl_log_levels_copy(&log_levels, &copied_log_levels));
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
EXPECT_EQ(RCL_RET_OK, rcl_log_levels_fini(&copied_log_levels));
});
EXPECT_EQ(RCUTILS_LOG_SEVERITY_UNSET, copied_log_levels.default_logger_level);
EXPECT_EQ(log_levels.default_logger_level, copied_log_levels.default_logger_level);
EXPECT_EQ(1ul, copied_log_levels.num_logger_settings);
Expand Down
1 change: 1 addition & 0 deletions rcl/test/rcl/test_security.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ TEST_F(TestGetSecureRoot, test_get_security_options) {
TEST_RESOURCES_DIRECTORY TEST_SECURITY_DIRECTORY_RESOURCES_DIR_NAME
PATH_SEPARATOR "enclaves" PATH_SEPARATOR TEST_ENCLAVE,
options.security_root_path);
EXPECT_EQ(RMW_RET_OK, rmw_security_options_fini(&options, &allocator));
}

TEST_F(TestGetSecureRoot, test_rcl_security_enabled) {
Expand Down
4 changes: 4 additions & 0 deletions rcl/test/rcl/test_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ TEST_F(CLASSNAME(TestServiceFixture, RMW_IMPLEMENTATION), test_fail_take_request

test_msgs__srv__BasicTypes_Request service_request;
test_msgs__srv__BasicTypes_Request__init(&service_request);
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
test_msgs__srv__BasicTypes_Request__fini(&service_request);
});
rmw_service_info_t header;

ret = rcl_take_request_with_info(nullptr, &header, &service_request);
Expand Down

0 comments on commit 78ed316

Please sign in to comment.