Skip to content

Commit c89776e

Browse files
authored
Fix memory leak in graph manager (#147)
Signed-off-by: Pablo Garrido <[email protected]>
1 parent 4a75022 commit c89776e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

micro_ros_agent/include/agent/graph_manager/graph_manager.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ class GraphManager
111111
const eprosima::fastdds::dds::DomainParticipant* participant,
112112
bool from_microros = true);
113113

114+
/**
115+
* @brief Getter for the graph cache.
116+
* @return Reference to inner graph cache
117+
*/
118+
rmw_dds_common::GraphCache& get_graph_cache() { return graphCache_; }
119+
114120
/**
115121
* @brief Adds a DDS datawriter to the graph tree.
116122
* @param datawriter_guid rtps::GUID_t of the datawriter to be added.

micro_ros_agent/src/agent/graph_manager/graph_manager.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ GraphManager::ParticipantListener::ParticipantListener(
597597
}
598598

599599
void GraphManager::ParticipantListener::on_participant_discovery(
600-
eprosima::fastdds::dds::DomainParticipant* participant,
600+
eprosima::fastdds::dds::DomainParticipant* /* participant */,
601601
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info)
602602
{
603603
switch (info.status)
@@ -614,13 +614,15 @@ void GraphManager::ParticipantListener::on_participant_discovery(
614614
const std::string enclave =
615615
std::string(name_found->second.begin(), name_found->second.end());
616616

617-
graphManager_from_->add_participant(participant, false, enclave);
617+
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", info.info.m_guid);
618+
graphManager_from_->get_graph_cache().add_participant(gid, enclave);
618619
break;
619620
}
620621
case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT:
621622
case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT:
622623
{
623-
graphManager_from_->remove_participant(participant, false);
624+
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", info.info.m_guid);
625+
graphManager_from_->get_graph_cache().remove_participant(gid);
624626
break;
625627
}
626628
default:

0 commit comments

Comments
 (0)