From 3e0fa4be66a95cbc6fd29835d7a749567cd3d5b0 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Wed, 6 Dec 2017 17:26:18 -0800 Subject: [PATCH] deallocate state and transition handles after call to fini (#424) * deallocate state and transition handles after call to fini * deallocate also when error occured --- rclcpp_lifecycle/src/state.cpp | 6 ++---- rclcpp_lifecycle/src/transition.cpp | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/rclcpp_lifecycle/src/state.cpp b/rclcpp_lifecycle/src/state.cpp index 9691472..a84f1d3 100644 --- a/rclcpp_lifecycle/src/state.cpp +++ b/rclcpp_lifecycle/src/state.cpp @@ -153,11 +153,9 @@ State::reset() return; } - // TODO(karsten1987): Fini currently deallocate the state_handle_ instance as well - // this should be changed to only deallocate members of the pointer so that stack - // variables can be correctly used as well. - // see https://github.com/ros2/rclcpp/pull/419#discussion_r155157098 auto ret = rcl_lifecycle_state_fini(state_handle_, &allocator_); + allocator_.deallocate(state_handle_, allocator_.state); + state_handle_ = nullptr; if (ret != RCL_RET_OK) { rclcpp::exceptions::throw_from_rcl_error(ret); } diff --git a/rclcpp_lifecycle/src/transition.cpp b/rclcpp_lifecycle/src/transition.cpp index ff64533..d7bae6c 100644 --- a/rclcpp_lifecycle/src/transition.cpp +++ b/rclcpp_lifecycle/src/transition.cpp @@ -257,11 +257,9 @@ Transition::reset() return; } - // TODO(karsten1987): Fini currently deallocate the transition_handle_ instance as well - // this should be changed to only deallocate members of the pointer so that stack - // variables can be correctly used as well. - // see https://github.com/ros2/rclcpp/pull/419#discussion_r155157098 auto ret = rcl_lifecycle_transition_fini(transition_handle_, &allocator_); + allocator_.deallocate(transition_handle_, allocator_.state); + transition_handle_ = nullptr; if (ret != RCL_RET_OK) { rclcpp::exceptions::throw_from_rcl_error(ret); }