Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory safe subscription callback #108

Draft
wants to merge 2 commits into
base: ros2
Choose a base branch
from

Conversation

ewak
Copy link

@ewak ewak commented Jan 11, 2025

Manage the lifetime of the bondStatusCB member function by wrapping it in a lambda that captures a weak_ptr (via public inheritance of std::enable_shared_from_this)

NOTE:
This is a draft to show how it could be done.

It solves a use after free that is being experienced using intraprocess communication in nav2 ros-navigation/navigation2#4691 .

Also being discussed as a bug in rclcpp - ros2/rclcpp#2678 (comment)

Something like createSafeSubscriptionMemFuncCallback could make its way into the rclcpp namespace.

ewak added 2 commits January 11, 2025 10:13
Inherit from std::enable_shared_from_this
and wrap subscription callback in lambda
capturing a weak_ptr using weak_from_this()
to check that Bond object is still
in scope before processing the bondStatusCB
member function.
Create and use helper function to check that
class is still valid before calling member function.
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.

1 participant