Skip to content

Fix memory leak in tracetools::get_symbol()#2104

Merged
mjcarroll merged 1 commit intoros2:rollingfrom
christophebedard:christophebedard/fix-memory-leak-in-tracetools-get-symbol
Feb 28, 2023
Merged

Fix memory leak in tracetools::get_symbol()#2104
mjcarroll merged 1 commit intoros2:rollingfrom
christophebedard:christophebedard/fix-memory-leak-in-tracetools-get-symbol

Conversation

@christophebedard
Copy link
Copy Markdown
Member

@christophebedard christophebedard commented Feb 15, 2023

Part of ros2/ros2_tracing#34

Requires ros2/ros2_tracing#43

Requires ros2/ros2_tracing#46 to help avoid memory allocations when the tracepoint isn't enabled.

Signed-off-by: Christophe Bedard christophe.bedard@apex.ai

@christophebedard
Copy link
Copy Markdown
Member Author

This is the simplest fix, but it could be improved. For example, we could first check if the tracepoint is actually enabled before calling tracetools::get_symbol() and allocating. This would require changes in tracetools, though. See ros2/ros2_tracing#43 (comment)

@alsora
Copy link
Copy Markdown
Collaborator

alsora commented Feb 15, 2023

Isn't the macro sufficient to prevent using this code if tracetools is disabled?
Or do we support both "compile time disabled" and "runtime disabled" ?

@mjcarroll
Copy link
Copy Markdown
Member

Or do we support both "compile time disabled" and "runtime disabled" ?

When building with tracepoints enabled, there will be some runtime associated here, even if the tracepoints are not actively being used. I think this is more important as we are discussing building with tracepoints by default in the binary packages.

@christophebedard
Copy link
Copy Markdown
Member Author

In this case, this tracepoint is only triggered during initialization, so the overhead is fairly small. But, yes, being able to not do this kind of processing if a tracepoint is disabled at runtime would be much better.

Since that change (as described here ros2/ros2_tracing#43 (comment)) requires modifications to tracetools and to potential downstream packages (including rclcpp for this exact instance), I could first add TRACEPOINT_ENABLED(...) and DO_TRACEPOINT(...) to tracetools. Then we'd only need to modify rclcpp once.

@christophebedard christophebedard force-pushed the christophebedard/fix-memory-leak-in-tracetools-get-symbol branch from 93bbc61 to 70d0953 Compare February 22, 2023 18:33
@christophebedard christophebedard marked this pull request as ready for review February 22, 2023 18:34
@christophebedard
Copy link
Copy Markdown
Member Author

christophebedard commented Feb 23, 2023

Testing --packages-above tracetools test_tracetools rclcpp:

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

Includes:

@christophebedard christophebedard force-pushed the christophebedard/fix-memory-leak-in-tracetools-get-symbol branch from 70d0953 to 41e046a Compare February 23, 2023 19:20
Signed-off-by: Christophe Bedard <christophe.bedard@apex.ai>
@christophebedard christophebedard force-pushed the christophebedard/fix-memory-leak-in-tracetools-get-symbol branch from 41e046a to 432d1f4 Compare February 23, 2023 21:27
Copy link
Copy Markdown
Member

@mjcarroll mjcarroll left a comment

Choose a reason for hiding this comment

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

Another approval for good measure

@christophebedard
Copy link
Copy Markdown
Member Author

@mjcarroll thanks 😆

I can't merge this PR, so I'll let you merge it.

@mjcarroll mjcarroll merged commit 72c05ec into ros2:rolling Feb 28, 2023
@christophebedard christophebedard deleted the christophebedard/fix-memory-leak-in-tracetools-get-symbol branch February 28, 2023 22:42
mjcarroll added a commit that referenced this pull request Mar 1, 2023
alsora pushed a commit to irobot-ros/rclcpp that referenced this pull request Apr 28, 2023
Signed-off-by: Christophe Bedard <christophe.bedard@apex.ai>
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.

3 participants