Skip to content

Commit

Permalink
Move the guard condition cleanup after removing callback. (#877)
Browse files Browse the repository at this point in the history
Otherwise, the callback could attempt to take a reference
to a guard condition that has already been deleted.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Jan 7, 2021
1 parent 38069b7 commit 31e1798
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions rcl/src/rcl/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,19 @@ rcl_timer_fini(rcl_timer_t * timer)
// Will return either RCL_RET_OK or RCL_RET_ERROR since the timer is valid.
rcl_ret_t result = rcl_timer_cancel(timer);
rcl_allocator_t allocator = timer->impl->allocator;
rcl_ret_t fail_ret = rcl_guard_condition_fini(&(timer->impl->guard_condition));
if (RCL_RET_OK != fail_ret) {
RCL_SET_ERROR_MSG("Failure to fini guard condition");
}
rcl_ret_t fail_ret;
if (RCL_ROS_TIME == timer->impl->clock->type) {
// The jump callbacks use the guard condition, so we have to remove it
// before freeing the guard condition below.
fail_ret = rcl_clock_remove_jump_callback(timer->impl->clock, _rcl_timer_time_jump, timer);
if (RCL_RET_OK != fail_ret) {
RCUTILS_LOG_ERROR_NAMED(ROS_PACKAGE_NAME, "Failed to remove timer jump callback");
}
}
fail_ret = rcl_guard_condition_fini(&(timer->impl->guard_condition));
if (RCL_RET_OK != fail_ret) {
RCL_SET_ERROR_MSG("Failure to fini guard condition");
}
allocator.deallocate(timer->impl, allocator.state);
timer->impl = NULL;
return result;
Expand Down

0 comments on commit 31e1798

Please sign in to comment.