Closed sumanth-nirmal closed 2 years ago
@eboasson @MatthiasKillat Can you please review the changes?
Currently, I am depending on iceoryx directly to free the chunk in serdata_free
under the assumption that we can remove this dependency once we update RMW to use the latest Cyclone tag. Please let me know if it doesn't make sense.
@eboasson Thanks for the comment, I did a code walkthrough for memory audit in the shared memory case and fixed a couple of memory leaks. I tried to summarize below the data path with allocations to identify if we missed anything
rmw_publish_serialized_message
dds_data_allocator
we loan the chunk from iceoryx (Chunk allocation)dds_writecdr()
serdata_rmw_free
(serdata free)serdata_rmw_free
(serdata free)rmw_publish_loaned_message
rmw_borrow_loaned_message
) (Chunk allocation)dds_writecdr()
serdata_rmw_free
(serdata free)dds_writecdr()
fails, serdata refcount is decremented, which will eventually free the serdata in serdata_rmw_free
(serdata free)rmw_take_serialized_message/with_info
dds_takecdr()
(serdata allocation)iox_chunk
(updated in serdata_rmw_from_iox
) (Chunk allocation)iox_chunk
will be released to the iox_subscriber in serdata_rmw_free
(Chunk free) serdata_rmw_free
(serdata free)serdata_rmw_free
iox_chunk
will be released to the iox_subscriber in serdata_rmw_free
(Chunk free) serdata_rmw_free
(serdata free)serdata_rmw_free
(serdata free)serdata_rmw_free
(serdata free)rmw_take_loaned_message/with_info
dds_takecdr()
(serdata allocation)iox_chunk
(updated in serdata_rmw_from_iox
) (Chunk allocation)
rmw_return_loaned_message_from_subscription()
(Chunk free)iox_chunk
pointer is reset to null
and serdata ref count is decremented (the ref count will be 0 after this)
serdata_rmw_free
(serdata free) \
(the loaned chunk will not be released here as the iox_chunk
pointer is null)rmw_return_loaned_message_from_subscription()
(Sample free)serdata_rmw_free
(serdata free)serdata_rmw_free
(serdata free)serdata_rmw_free
(serdata free)I think with this MR, all the previously unhandled memory leaks with SHM should have been fixed (unless I missed anything)!
@eboasson I see that linters fail in the CI jobs here https://github.com/ros2/rmw_cyclonedds/pull/365#pullrequestreview-871457535, but then realized that these are already fixed in this PR https://github.com/ros2/rmw_cyclonedds/pull/363. I have now rebased this branch onto the latest master and the CI should hopefully be good now. Can you please run the CI again?
@clalancette I notice that GitHub says your review was requested and I don't to go ahead and merge it if there's a possibility that you're reviewing it at the same time. As far as I am concerned, this is good to go. Please let me know (or simply press "merge" as a way of letting me know 🙂)
Fixes #364