Fix mem leaks in unit test from 776 (#779)
Signed-off-by: Stephen Brawner <brawner@gmail.com>
This commit is contained in:
parent
bf2029acf8
commit
a34c4816c9
2 changed files with 34 additions and 17 deletions
|
@ -313,9 +313,12 @@ TEST(test_file_parser, seq_map1) {
|
||||||
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
||||||
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
||||||
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
|
});
|
||||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||||
EXPECT_FALSE(res);
|
EXPECT_FALSE(res);
|
||||||
// No cleanup, rcl_parse_yaml_file takes care of that if it fails.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_file_parser, seq_map2) {
|
TEST(test_file_parser, seq_map2) {
|
||||||
|
@ -337,9 +340,12 @@ TEST(test_file_parser, seq_map2) {
|
||||||
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
||||||
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
||||||
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
|
});
|
||||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||||
EXPECT_FALSE(res);
|
EXPECT_FALSE(res);
|
||||||
// No cleanup, rcl_parse_yaml_file takes care of that if it fails
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_file_parser, params_with_no_node) {
|
TEST(test_file_parser, params_with_no_node) {
|
||||||
|
@ -361,9 +367,12 @@ TEST(test_file_parser, params_with_no_node) {
|
||||||
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
||||||
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
||||||
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
|
});
|
||||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||||
EXPECT_FALSE(res);
|
EXPECT_FALSE(res);
|
||||||
// No cleanup, rcl_parse_yaml_file takes care of that if it fails.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_file_parser, no_alias_support) {
|
TEST(test_file_parser, no_alias_support) {
|
||||||
|
@ -385,9 +394,12 @@ TEST(test_file_parser, no_alias_support) {
|
||||||
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
||||||
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
||||||
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
|
});
|
||||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||||
EXPECT_FALSE(res);
|
EXPECT_FALSE(res);
|
||||||
// No cleanup, rcl_parse_yaml_file takes care of that if it fails.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_file_parser, empty_string) {
|
TEST(test_file_parser, empty_string) {
|
||||||
|
@ -437,9 +449,12 @@ TEST(test_file_parser, no_value1) {
|
||||||
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
||||||
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
||||||
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
|
});
|
||||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||||
EXPECT_FALSE(res);
|
EXPECT_FALSE(res);
|
||||||
// No cleanup, rcl_parse_yaml_file takes care of that if it fails.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_file_parser, indented_ns) {
|
TEST(test_file_parser, indented_ns) {
|
||||||
|
@ -461,9 +476,12 @@ TEST(test_file_parser, indented_ns) {
|
||||||
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
||||||
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
||||||
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
|
});
|
||||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||||
EXPECT_FALSE(res);
|
EXPECT_FALSE(res);
|
||||||
// No cleanup, rcl_parse_yaml_file takes care of that if it fails.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regression test for https://github.com/ros2/rcl/issues/419
|
// Regression test for https://github.com/ros2/rcl/issues/419
|
||||||
|
@ -486,9 +504,12 @@ TEST(test_file_parser, maximum_number_parameters) {
|
||||||
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
|
||||||
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
||||||
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
|
});
|
||||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||||
EXPECT_FALSE(res);
|
EXPECT_FALSE(res);
|
||||||
// No cleanup, rcl_parse_yaml_file takes care of that if it fails.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test special float point(https://github.com/ros2/rcl/issues/555).
|
// Test special float point(https://github.com/ros2/rcl/issues/555).
|
||||||
|
|
|
@ -330,11 +330,9 @@ TEST(RclYamlParamParser, test_parse_file_with_bad_allocator) {
|
||||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||||
// Not verifying res is true or false here, because eventually it will come back with an ok
|
// Not verifying res is true or false here, because eventually it will come back with an ok
|
||||||
// result. We're just trying to make sure that bad allocations are properly handled
|
// result. We're just trying to make sure that bad allocations are properly handled
|
||||||
if (res) {
|
(void)res;
|
||||||
// This is already freed in the case of a non-ok error in rcl_parse_yaml_file
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
rcl_yaml_node_struct_fini(params_hdl);
|
params_hdl = NULL;
|
||||||
params_hdl = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check sporadic failing calloc calls
|
// Check sporadic failing calloc calls
|
||||||
|
@ -347,11 +345,9 @@ TEST(RclYamlParamParser, test_parse_file_with_bad_allocator) {
|
||||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||||
// Not verifying res is true or false here, because eventually it will come back with an ok
|
// Not verifying res is true or false here, because eventually it will come back with an ok
|
||||||
// result. We're just trying to make sure that bad allocations are properly handled
|
// result. We're just trying to make sure that bad allocations are properly handled
|
||||||
if (res) {
|
(void)res;
|
||||||
// This is already freed in the case of a non-ok error in rcl_parse_yaml_file
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
rcl_yaml_node_struct_fini(params_hdl);
|
params_hdl = NULL;
|
||||||
params_hdl = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue