Skip to content

Memory leak from enclave #311

@jimmy-mcelwain

Description

@jimmy-mcelwain

Describe the bug
Context ros2/rcl#1198 and Yaskawa-Global/motoros2#35

I believe that there is a possible memory leak in rmw_microxrcedds. In the micro-ROS rcl repo, the following lines duplicate a string and dynamically allocate the memory if RCL_MICROROS_COMPLETE_IMPL is set.

https://github.com/micro-ROS/rcl/blob/041a67a2e102e9c48ae2580f19b2677016fcf86a/rcl/src/rcl/init.c#L265-L273

This memory which is dynamically allocated for enclave via rcutils_strdup is deallocated in other (full) rmw implementations. For example:

https://github.com/ros2/rmw_fastrtps/blob/1128b57d336dfa8bf462a5f9147291f73faa8ed3/rmw_fastrtps_shared_cpp/src/rmw_init.cpp#L116

However it is never deallocated in rmw_microxrcedds. I believe that this is only a problem if RCL_MICROROS_COMPLETE_IMPL is set, because that is the only case where rcutils_strdup runs and sets aside dynamic memory.

I do not believe that the solution is as simple as freeing the memory in rmw_init_options_fini, because the code below copies the enclave data to static memory, and thus cannot be freed. I might be wrong about that.

https://github.com/micro-ROS/rcl/blob/041a67a2e102e9c48ae2580f19b2677016fcf86a/rcl/src/rcl/init.c#L105-L110

To Reproduce
I do not have a MWE, but it is apparent in MotoROS2 using the debug listener script. edit - I have a MWE below

Expected behaviour
I expect the memory set aside by rcutils_strdup to be freed by the rmw, as it is with other rmws.

System information (please complete the following information):

  • YRC1000
  • ROS 2: I am currently using Jazzy. I believe that the problem exists on Humble as well, though.
  • Version: I am currently using a fork off of 2.4.3

Please let me know if I need to provide any more information, or if I am doing something improperly. Thank you.

Metadata

Metadata

Assignees

No one assigned

    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