Make sure timer is fini'd before clock (#553)

* Make sure timer is fini'd before clock
This commit is contained in:
Shane Loretz 2018-09-07 17:28:10 -07:00 committed by GitHub
parent 8c6f38a0fa
commit b1af28047c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,7 +27,7 @@ TimerBase::TimerBase(rclcpp::Clock::SharedPtr clock, std::chrono::nanoseconds pe
clock_ = clock; clock_ = clock;
timer_handle_ = std::shared_ptr<rcl_timer_t>( timer_handle_ = std::shared_ptr<rcl_timer_t>(
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) { if (rcl_timer_fini(timer) != RCL_RET_OK) {
RCUTILS_LOG_ERROR_NAMED( RCUTILS_LOG_ERROR_NAMED(
@ -36,6 +36,8 @@ TimerBase::TimerBase(rclcpp::Clock::SharedPtr clock, std::chrono::nanoseconds pe
rcl_reset_error(); rcl_reset_error();
} }
delete timer; 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(); *timer_handle_.get() = rcl_get_zero_initialized_timer();