Repository navigation
Description
Host: YRC1000 running MotoROS2
Client: PC running Ubuntu 22.04
ROS2 version: Humble
Commits: The commit hashes/version used to build MotoROS2 are available here
DDS: FastDDS
I am a contributor to MotoROS2. Our implementation allows the controller and client to be disconnected/reconnected repeatedly. Whenever I disconnect the client pc from the host, the memory is freed and everything is shut down, and then everything is re-initialized upon connecting again. However, I noticed a memory leak, 24 bytes per disconnect/reconnect cycle. I eventually traced it to its source and found the leak.
Lines 216 to 223 in 2615b0e
| if (context->global_arguments.impl->enclave) { | |
| context->impl->init_options.impl->rmw_init_options.enclave = rcutils_strdup( | |
| context->global_arguments.impl->enclave, | |
| context->impl->allocator); | |
| } else { | |
| context->impl->init_options.impl->rmw_init_options.enclave = rcutils_strdup( | |
| "/", context->impl->allocator); | |
| } |
The memory allocated in these strdup calls is never freed.
I have a branch on our fork of micro-ros here where I added a single line freeing the memory allocated in that strdup, and the memory leak disappeared. There is now no memory lost with a connect/disconnect cycle.
I noticed the problem in Motoman's own fork of micro-ros/rcl, which is somewhat outdated. But looking through the up-to-date upstream repos, the problem is seemingly present in micro-ros/rcl as well as here. Not just in humble, but in newer distributions/rolling as well.
I do not know if the spot that I freed the memory is the proper spot to do so. But if I understand correctly, it has not yet been fixed upstream (here) and the proper spot to free the memory is somewhere in this repo.
Activity
fujitatomoya commentedon Nov 16, 2024
did you confirm the there is a memory leak on
ros2/rcl (rolling)?it looks like it frees the memory here.
rcl/rcl/src/rcl/context.c
Line 135 in 2615b0e
rcl/rcl/src/rcl/init_options.c
Line 138 in 2615b0e
and i see underlying all rmw tier 1 implementation free the memory for
enclave.jimmy-mcelwain commentedon Dec 10, 2024
Sorry for the late response, but thank you. I was unaware that it was the responsibility of the rmw to free that memory. I thought that it was the responsibility of rcl. I am using rmw_microxrcedds. I took a look there, and it seems to me like enclave is not freed if
RCL_MICROROS_COMPLETE_IMPLis set. I opened up an issue at micro-ROS/rmw_microxrcedds#311.