diff --git a/rclcpp/src/rclcpp/timer.cpp b/rclcpp/src/rclcpp/timer.cpp index b38e2fe..9922beb 100644 --- a/rclcpp/src/rclcpp/timer.cpp +++ b/rclcpp/src/rclcpp/timer.cpp @@ -27,7 +27,7 @@ TimerBase::TimerBase(rclcpp::Clock::SharedPtr clock, std::chrono::nanoseconds pe clock_ = clock; timer_handle_ = std::shared_ptr( - new rcl_timer_t, [ = ](rcl_timer_t * timer) + new rcl_timer_t, [ = ](rcl_timer_t * timer) mutable { if (rcl_timer_fini(timer) != RCL_RET_OK) { RCUTILS_LOG_ERROR_NAMED( @@ -36,6 +36,8 @@ TimerBase::TimerBase(rclcpp::Clock::SharedPtr clock, std::chrono::nanoseconds pe rcl_reset_error(); } delete timer; + // Captured shared pointer by copy, reset to make sure timer is finalized before clock + clock.reset(); }); *timer_handle_.get() = rcl_get_zero_initialized_timer();