Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions rclcpp/src/rclcpp/generic_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -90,9 +91,21 @@ GenericClient::create_response()
std::shared_ptr<rmw_request_id_t>
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<rmw_request_id_t>(new rmw_request_id_t);
rcutils_allocator_t allocator = rcutils_get_default_allocator();

rmw_request_id_t * request_header =
static_cast<rmw_request_id_t *>(allocator.zero_allocate(1, sizeof(rmw_request_id_t), allocator.state));

if (!request_header) {
throw std::bad_alloc();
}

return std::shared_ptr<rmw_request_id_t>(
request_header,
[allocator](rmw_request_id_t * p) mutable
{
allocator.deallocate(p, allocator.state);
});
}

void
Expand Down