Skip to content

Fix ASAN / valgrind warnings due to C / C++ allocator mismatch#3054

Open
jmachowinski wants to merge 2 commits intoros2:rollingfrom
cellumation:get_rcl_allocator
Open

Fix ASAN / valgrind warnings due to C / C++ allocator mismatch#3054
jmachowinski wants to merge 2 commits intoros2:rollingfrom
cellumation:get_rcl_allocator

Conversation

@jmachowinski
Copy link
Collaborator

Description

rclcpp passes down C++ style allocators down to rcl, that then uses them.
Due to the missing / wrong size on the deallocation, all the memory checkers
complain about it in newer ubuntu versions (>= 24.04).
This PR is a rebase / rework of #2046

Did you use Generative AI?

No

stevewolter and others added 2 commits February 6, 2026 18:32
As explained in ros2#1254, there's conceptually no way to implement RCL
allocators in terms of C++ allocators. In order to fix this behavior,
we have to delete the generic version of get_rcl_allocator. Since some
ROS code depends on this, we need to allow users to write their own
version of get_rcl_allocator for allocators that support the C-style
interface (most do).

So this CL changes get_rcl_allocator from a template function
into a family of (potentially templated) functions, which allows
users to add their own overloads and rely on the "most specialized"
mechanism for function specialization to select the right one. See
http://www.gotw.ca/publications/mill17.htm for details. This also
allows us to return get_rcl_default_allocator for all specializations
of std::allocator (previously, only for std::allocator), which will
already fix ros2#1254 for pretty much all clients. I'll continue to work
on deleting the generic version, though, to make sure that nobody is
accidentally bitten by it.

I've tried to test this by doing a full ROS compilation following the
Dockerfile of the source Docker image, and all packages compile.

Signed-off-by: Steve Wolter <swolter@google.com>

Addressed code style test failures.

Signed-off-by: Steve Wolter <swolter@google.com>

Update comments.

Incidentally, this also reruns the flaky test suite, which
seems to be using the real DDS middleware and to be prone
to cross-talk.

Signed-off-by: Steve Wolter <swolter@google.com>

Also update recently added tests.

Signed-off-by: Steve Wolter <swolter@google.com>

Added reference to bug number.

Signed-off-by: Steve Wolter <swolter@google.com>

Extend allocator lifetime in options.

Signed-off-by: Steve Wolter <swolter@google.com>

Drop the generic version of get_rcl_allocator.

This allows us to simplify a bunch of code as well.

Signed-off-by: Steve Wolter <swolter@google.com>

Update rclcpp/include/rclcpp/allocator/allocator_common.hpp

Co-authored-by: William Woodall <william+github@osrfoundation.org>
Signed-off-by: Steve Wolter <swolter@google.com>

Revert accidental deletion of allocator creation.

Signed-off-by: Steve Wolter <swolter@google.com>
Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>
@jmachowinski
Copy link
Collaborator Author

Pulls: #3054
Gist: https://gist.githubusercontent.com/jmachowinski/7285e1d444daa056eaf9ff06a51751fb/raw/175976e96bf0ca359ab3f6f654faf0717ae9a4e7/ros2.repos
BUILD args:
TEST args:
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18143

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants