From 6d4a8284e48e438a87888832052bff1954d6bb89 Mon Sep 17 00:00:00 2001 From: mauropasse Date: Fri, 23 Sep 2022 00:30:59 +0100 Subject: [PATCH] Do not clear entities callbacks on destruction (#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 * Fix CI Signed-off-by: Mauro Passerino * 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 * Add coment on clearing callback for QoS event Signed-off-by: Mauro Passerino Signed-off-by: Mauro Passerino Co-authored-by: Mauro Passerino --- rclcpp/src/rclcpp/event_handler.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rclcpp/src/rclcpp/event_handler.cpp b/rclcpp/src/rclcpp/event_handler.cpp index d4b4d57b08..804146d4d7 100644 --- a/rclcpp/src/rclcpp/event_handler.cpp +++ b/rclcpp/src/rclcpp/event_handler.cpp @@ -39,6 +39,15 @@ UnsupportedEventTypeException::UnsupportedEventTypeException( EventHandlerBase::~EventHandlerBase() { + // Since the rmw event listener holds a reference to + // this callback, we need to clear it on destruction of this class. + // This clearing is not needed for other rclcpp entities like pub/subs, since + // they do own the underlying rmw entities, which are destroyed + // on their rclcpp destructors, thus no risk of dangling pointers. + if (on_new_event_callback_) { + clear_on_ready_callback(); + } + if (rcl_event_fini(&event_handle_) != RCL_RET_OK) { RCUTILS_LOG_ERROR_NAMED( "rclcpp",