From 63c72e9ffb16dbb5bba0dd100f2a6dbb35e6ed57 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Mon, 31 Aug 2020 16:56:07 -0300 Subject: [PATCH] Fix rcl_parse_yaml_file() error handling. (#776) It should not fini its output argument, silently invalidating the given pointer. Signed-off-by: Michel Hidalgo --- .../include/rcl_yaml_param_parser/parser.h | 6 ++++-- rcl_yaml_param_parser/src/parser.c | 7 +------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h b/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h index 3243b43de..293e1fbf1 100644 --- a/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h +++ b/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h @@ -57,9 +57,11 @@ RCL_YAML_PARAM_PARSER_PUBLIC void rcl_yaml_node_struct_fini( rcl_params_t * params_st); -/// \brief Parse the YAML file, initialize and populate params_st +/// \brief Parse the YAML file and populate \p params_st +/// \pre Given \p params_st must be a valid parameter struct +/// as returned by `rcl_yaml_node_struct_init()` /// \param[in] file_path is the path to the YAML file -/// \param[inout] params_st points to the populated parameter struct +/// \param[inout] params_st points to the struct to be populated /// \return true on success and false on failure RCL_YAML_PARAM_PARSER_PUBLIC bool rcl_parse_yaml_file( diff --git a/rcl_yaml_param_parser/src/parser.c b/rcl_yaml_param_parser/src/parser.c index 814da9da4..b23e4e4cd 100644 --- a/rcl_yaml_param_parser/src/parser.c +++ b/rcl_yaml_param_parser/src/parser.c @@ -1810,12 +1810,7 @@ bool rcl_parse_yaml_file( allocator.deallocate(ns_tracker.parameter_ns, allocator.state); } - if (RCUTILS_RET_OK != ret) { - rcl_yaml_node_struct_fini(params_st); - return false; - } - - return true; + return RCUTILS_RET_OK == ret; } ///