Skip to content

Commit 5ee345b

Browse files
mauropasseMauro Passerino
authored andcommitted
Do not clear entities callbacks on destruction (ros2#2002)
* Do not clear entities callbacks on destruction Removing these clearings since they were not necessary, since the objects are being destroyed anyway. Signed-off-by: Mauro Passerino <[email protected]> * Fix CI Signed-off-by: Mauro Passerino <[email protected]> * Restore clear_on_ready_callback on ~QOSEventHandlerBase Needed since QOSEventHandlerBase does not own the pub/sub listeners. So the QOSEventHandler can be destroyed while the corresponding listeners are still alive, so we need to clear these callbacks. Signed-off-by: Mauro Passerino <[email protected]> * Add coment on clearing callback for QoS event Signed-off-by: Mauro Passerino <[email protected]> Signed-off-by: Mauro Passerino <[email protected]> Co-authored-by: Mauro Passerino <[email protected]>
1 parent 735a784 commit 5ee345b

File tree

7 files changed

+6
-20
lines changed

7 files changed

+6
-20
lines changed

rclcpp/include/rclcpp/experimental/subscription_intra_process_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SubscriptionIntraProcessBase : public rclcpp::Waitable
5252
{}
5353

5454
RCLCPP_PUBLIC
55-
virtual ~SubscriptionIntraProcessBase();
55+
virtual ~SubscriptionIntraProcessBase() = default;
5656

5757
RCLCPP_PUBLIC
5858
size_t

rclcpp/src/rclcpp/publisher_base.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ PublisherBase::PublisherBase(
102102

103103
PublisherBase::~PublisherBase()
104104
{
105-
for (const auto & pair : event_handlers_) {
106-
rcl_publisher_event_type_t event_type = pair.first;
107-
clear_on_new_qos_event_callback(event_type);
108-
}
109-
110105
// must fini the events before fini-ing the publisher
111106
event_handlers_.clear();
112107

rclcpp/src/rclcpp/qos_event.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ UnsupportedEventTypeException::UnsupportedEventTypeException(
3535

3636
QOSEventHandlerBase::~QOSEventHandlerBase()
3737
{
38+
// Since the rmw event listener holds a reference to
39+
// this callback, we need to clear it on destruction of this class.
40+
// This clearing is not needed for other rclcpp entities like pub/subs, since
41+
// they do own the underlying rmw entities, which are destroyed
42+
// on their rclcpp destructors, thus no risk of dangling pointers.
3843
if (on_new_event_callback_) {
3944
clear_on_ready_callback();
4045
}

rclcpp/src/rclcpp/subscription_base.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ SubscriptionBase::SubscriptionBase(
8787

8888
SubscriptionBase::~SubscriptionBase()
8989
{
90-
clear_on_new_message_callback();
91-
92-
for (const auto & pair : event_handlers_) {
93-
rcl_subscription_event_type_t event_type = pair.first;
94-
clear_on_new_qos_event_callback(event_type);
95-
}
96-
9790
if (!use_intra_process_) {
9891
return;
9992
}

rclcpp/src/rclcpp/subscription_intra_process_base.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
using rclcpp::experimental::SubscriptionIntraProcessBase;
1919

20-
SubscriptionIntraProcessBase::~SubscriptionIntraProcessBase()
21-
{
22-
clear_on_ready_callback();
23-
}
24-
2520
void
2621
SubscriptionIntraProcessBase::add_to_wait_set(rcl_wait_set_t * wait_set)
2722
{

rclcpp_action/src/client.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ ClientBase::ClientBase(
136136

137137
ClientBase::~ClientBase()
138138
{
139-
clear_on_ready_callback();
140139
}
141140

142141
bool

rclcpp_action/src/server.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ ServerBase::ServerBase(
132132

133133
ServerBase::~ServerBase()
134134
{
135-
clear_on_ready_callback();
136135
}
137136

138137
size_t

0 commit comments

Comments
 (0)