Skip to content

Commit 6d4a828

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 c1a01fc commit 6d4a828

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

rclcpp/src/rclcpp/event_handler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ UnsupportedEventTypeException::UnsupportedEventTypeException(
3939

4040
EventHandlerBase::~EventHandlerBase()
4141
{
42+
// Since the rmw event listener holds a reference to
43+
// this callback, we need to clear it on destruction of this class.
44+
// This clearing is not needed for other rclcpp entities like pub/subs, since
45+
// they do own the underlying rmw entities, which are destroyed
46+
// on their rclcpp destructors, thus no risk of dangling pointers.
47+
if (on_new_event_callback_) {
48+
clear_on_ready_callback();
49+
}
50+
4251
if (rcl_event_fini(&event_handle_) != RCL_RET_OK) {
4352
RCUTILS_LOG_ERROR_NAMED(
4453
"rclcpp",

0 commit comments

Comments
 (0)