Skip to content

Commit d488535

Browse files
authored
[service] Don't use a weak_ptr to avoid leaking (#1668)
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
1 parent 72443ff commit d488535

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

rclcpp/include/rclcpp/service.hpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,16 @@ class Service : public ServiceBase
177177
using rosidl_typesupport_cpp::get_service_type_support_handle;
178178
auto service_type_support_handle = get_service_type_support_handle<ServiceT>();
179179

180-
std::weak_ptr<rcl_node_t> weak_node_handle(node_handle_);
181180
// rcl does the static memory allocation here
182181
service_handle_ = std::shared_ptr<rcl_service_t>(
183-
new rcl_service_t, [weak_node_handle, service_name](rcl_service_t * service)
182+
new rcl_service_t, [handle = node_handle_, service_name](rcl_service_t * service)
184183
{
185-
auto handle = weak_node_handle.lock();
186-
if (handle) {
187-
if (rcl_service_fini(service, handle.get()) != RCL_RET_OK) {
188-
RCLCPP_ERROR(
189-
rclcpp::get_node_logger(handle.get()).get_child("rclcpp"),
190-
"Error in destruction of rcl service handle: %s",
191-
rcl_get_error_string().str);
192-
rcl_reset_error();
193-
}
194-
} else {
195-
RCLCPP_ERROR_STREAM(
196-
rclcpp::get_logger("rclcpp"),
197-
"Error in destruction of rcl service handle " << service_name <<
198-
": the Node Handle was destructed too early. You will leak memory");
184+
if (rcl_service_fini(service, handle.get()) != RCL_RET_OK) {
185+
RCLCPP_ERROR(
186+
rclcpp::get_node_logger(handle.get()).get_child("rclcpp"),
187+
"Error in destruction of rcl service handle: %s",
188+
rcl_get_error_string().str);
189+
rcl_reset_error();
199190
}
200191
delete service;
201192
});

0 commit comments

Comments
 (0)