From f85b3ee8d7b61fb75c0f96a8631384ca48919dfa Mon Sep 17 00:00:00 2001 From: Pablo Garrido Date: Wed, 8 Jun 2022 14:12:55 +0200 Subject: [PATCH] Fix memory leak in graph manager (#147) Signed-off-by: Pablo Garrido (cherry picked from commit c89776e1fd2b7a08f0bcdccdf0d40e4287b28b1f) --- .../include/agent/graph_manager/graph_manager.hpp | 6 ++++++ micro_ros_agent/src/agent/graph_manager/graph_manager.cpp | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/micro_ros_agent/include/agent/graph_manager/graph_manager.hpp b/micro_ros_agent/include/agent/graph_manager/graph_manager.hpp index 7ea044f..fb424b1 100644 --- a/micro_ros_agent/include/agent/graph_manager/graph_manager.hpp +++ b/micro_ros_agent/include/agent/graph_manager/graph_manager.hpp @@ -111,6 +111,12 @@ class GraphManager const eprosima::fastdds::dds::DomainParticipant* participant, bool from_microros = true); + /** + * @brief Getter for the graph cache. + * @return Reference to inner graph cache + */ + rmw_dds_common::GraphCache& get_graph_cache() { return graphCache_; } + /** * @brief Adds a DDS datawriter to the graph tree. * @param datawriter_guid rtps::GUID_t of the datawriter to be added. diff --git a/micro_ros_agent/src/agent/graph_manager/graph_manager.cpp b/micro_ros_agent/src/agent/graph_manager/graph_manager.cpp index a05b3a7..4dce46d 100644 --- a/micro_ros_agent/src/agent/graph_manager/graph_manager.cpp +++ b/micro_ros_agent/src/agent/graph_manager/graph_manager.cpp @@ -633,7 +633,7 @@ GraphManager::ParticipantListener::ParticipantListener( } void GraphManager::ParticipantListener::on_participant_discovery( - eprosima::fastdds::dds::DomainParticipant* participant, + eprosima::fastdds::dds::DomainParticipant* /* participant */, eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) { switch (info.status) @@ -650,13 +650,15 @@ void GraphManager::ParticipantListener::on_participant_discovery( const std::string enclave = std::string(name_found->second.begin(), name_found->second.end()); - graphManager_from_->add_participant(participant, false, enclave); + const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", info.info.m_guid); + graphManager_from_->get_graph_cache().add_participant(gid, enclave); break; } case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT: case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT: { - graphManager_from_->remove_participant(participant, false); + const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", info.info.m_guid); + graphManager_from_->get_graph_cache().remove_participant(gid); break; } default: