From 4ebc0cd082f22e612cf5eeb8f0c6f5f43eab3a45 Mon Sep 17 00:00:00 2001 From: Pietro Gelmini <86184562+Gelminaio@users.noreply.github.com> Date: Tue, 12 May 2026 10:55:28 +0200 Subject: [PATCH] refactor: resolve TODO to use allocator for rmw_request_id_t in GenericClient Signed-off-by: Pietro Gelmini <86184562+Gelminaio@users.noreply.github.com> --- rclcpp/src/rclcpp/generic_client.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/rclcpp/src/rclcpp/generic_client.cpp b/rclcpp/src/rclcpp/generic_client.cpp index ed669cd002..f2ba1b92d1 100644 --- a/rclcpp/src/rclcpp/generic_client.cpp +++ b/rclcpp/src/rclcpp/generic_client.cpp @@ -20,6 +20,7 @@ #include "rosidl_runtime_c/service_type_support_struct.h" #include "rosidl_typesupport_introspection_cpp/identifier.hpp" #include "rosidl_typesupport_introspection_cpp/service_introspection.hpp" +#include "rcutils/allocator.h" namespace rclcpp { @@ -90,9 +91,21 @@ GenericClient::create_response() std::shared_ptr GenericClient::create_request_header() { - // TODO(wjwwood): This should probably use rmw_request_id's allocator. - // (since it is a C type) - return std::shared_ptr(new rmw_request_id_t); + rcutils_allocator_t allocator = rcutils_get_default_allocator(); + + rmw_request_id_t * request_header = + static_cast(allocator.zero_allocate(1, sizeof(rmw_request_id_t), allocator.state)); + + if (!request_header) { + throw std::bad_alloc(); + } + + return std::shared_ptr( + request_header, + [allocator](rmw_request_id_t * p) mutable + { + allocator.deallocate(p, allocator.state); + }); } void