Skip to content

Publisher and subscription options pass dangling pointer to get_rcl_allocator #1339

Description

@stevewolter

In rclcpp/include/rclcpp/subscription_options.hpp and rclcpp/include/rclcpp/publisher_options.hpp, the conversion to RCL options ("to_rcl_publisher_options") passes a reference to a C++ allocator that goes out of scope at the end of the function:

auto message_alloc = std::make_shared<MessageAllocatorT>(*this->get_allocator().get());
result.allocator = get_rcl_allocator(*message_alloc);

This could cause unexpected problems for users of custom allocators when they reference the allocator in an overload of get_rcl_allocator. Standard ROS code is not affected, because neither std::allocator nor tlsf_allocator carry internal state. This is hard to fix, because neither rcl_publisher_options_t nor rcl_allocator_t have destructors (so they can't just create their own reference to the shared_ptr).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions