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