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

tf2_ros: add virtual destructor to tf2_ros::BufferInterface #560

Open
wants to merge 1 commit into
base: noetic-devel
Choose a base branch
from

Conversation

meyerj
Copy link
Contributor

@meyerj meyerj commented Feb 3, 2024

Same as #346, targeting noetic-devel:

Class tf2_ros::BufferInterface did not define a virtual destructor, but has virtual methods. This is dangerous because it may lead to memory leaks if instances are deleted using a pointer to the base class (reference: https://stackoverflow.com/questions/1123044/when-should-your-destructor-be-virtual).

Clang and GCC with -Wnon-virtual-dtor or -Weffc++ warn about this:

include/tf2_ros/buffer_interface.h:48:7: warning: 'tf2_ros::BufferInterface' has virtual functions but non-virtual destructor [-Wnon-virtual-dtor]                                                             
class BufferInterface                                                                                                                                                                                                                  
      ^                                                     

Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meyerj
Copy link
Contributor Author

meyerj commented Feb 5, 2024

I assume this comment still applies:

This looks right, but I believe it will break ABI so we'll need to evaulate whether an ABI change or memory leak is worse. In general since we rebuild everything right now I think the ABI change is likely less of an issue.

So the patch cannot be merged into noetic-devel without breaking the ABI, but should probably have been considered for a new distribution in between. Overall, the severity of the potential memory leak is low, because likely in most applications tf buffers will be created and destroyed once, and not deleted repeatedly via a tf2_ros::BufferInterface pointer. So it may be fine to keep it as-is and close the PR, given that there will be no future ROS 1 release anymore?

By the way, for ROS 2 the same issue has been addressed in ros2/geometry2@5178d48.

@meyerj
Copy link
Contributor Author

meyerj commented Apr 25, 2024

What is the policy of breaking the ABI on branch noetic-devel? If ABI breaking changes are not accepted anyway, for a good reason, then maybe I should re-submit this to https://github.com/ros-o/geometry2?

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