Skip to content

Commit

Permalink
fix memory leak (ros2#1994)
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
  • Loading branch information
Chen Lihui authored and Alberto Soragna committed May 3, 2023
1 parent 51b032e commit 5a96a47
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rclcpp/src/rclcpp/parameter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <string>
#include <vector>

#include "rcpputils/find_and_replace.hpp"
#include "rcpputils/scope_exit.hpp"
#include "rclcpp/parameter_map.hpp"

using rclcpp::exceptions::InvalidParametersException;
Expand Down Expand Up @@ -132,9 +134,11 @@ rclcpp::parameter_map_from_yaml_file(const std::string & yaml_filename)
{
rcutils_allocator_t allocator = rcutils_get_default_allocator();
rcl_params_t * rcl_parameters = rcl_yaml_node_struct_init(allocator);
RCPPUTILS_SCOPE_EXIT(rcl_yaml_node_struct_fini(rcl_parameters); );
const char * path = yaml_filename.c_str();
if (!rcl_parse_yaml_file(path, rcl_parameters)) {
rclcpp::exceptions::throw_from_rcl_error(RCL_RET_ERROR);
}

return rclcpp::parameter_map_from(rcl_parameters);
}

0 comments on commit 5a96a47

Please sign in to comment.