Skip to content

Commit

Permalink
fix clock cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Jul 27, 2018
1 parent bc47e31 commit c788ec0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rclpy/rclpy/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class WallTimer:

def __init__(self, callback, callback_group, timer_period_ns):
[self.timer_handle, self.timer_pointer] = _rclpy.rclpy_create_timer(timer_period_ns)
[self.timer_handle, self.timer_pointer, _] = _rclpy.rclpy_create_timer(timer_period_ns)
self.timer_period_ns = timer_period_ns
self.callback = callback
self.callback_group = callback_group
Expand Down
23 changes: 15 additions & 8 deletions rclpy/src/rclpy/_rclpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,9 +1218,9 @@ rclpy_create_timer(PyObject * Py_UNUSED(self), PyObject * args)
return NULL;
}
PyObject * pylist = PyList_New(3);
PyList_SET_ITEM(pylist, 0, PyCapsule_New(clock, "rcl_clock_t", NULL));
PyList_SET_ITEM(pylist, 1, PyCapsule_New(timer, "rcl_timer_t", NULL));
PyList_SET_ITEM(pylist, 2, PyLong_FromUnsignedLongLong((uint64_t)&timer->impl));
PyList_SET_ITEM(pylist, 0, PyCapsule_New(timer, "rcl_timer_t", NULL));
PyList_SET_ITEM(pylist, 1, PyLong_FromUnsignedLongLong((uint64_t)&timer->impl));
PyList_SET_ITEM(pylist, 2, PyCapsule_New(clock, "rcl_clock_t", NULL));

return pylist;
}
Expand Down Expand Up @@ -2073,18 +2073,25 @@ rclpy_destroy_entity(PyObject * Py_UNUSED(self), PyObject * args)
PyMem_Free(node);
} else if (PyCapsule_IsValid(pyentity, "rcl_timer_t")) {
rcl_timer_t * timer = (rcl_timer_t *)PyCapsule_GetPointer(pyentity, "rcl_timer_t");
ret = rcl_timer_fini(timer);
PyMem_Free(timer);

rcl_clock_t * clock = (rcl_clock_t *)PyCapsule_GetPointer(pyentity, "rcl_clock_t");
rcl_clock_t * clock = 0;
ret = rcl_timer_clock(timer, &clock);
if (ret != RCL_RET_OK) {
PyErr_Format(PyExc_RuntimeError,
"Failed to get 'rcl_clock_t' from timer: %s", rcl_get_error_string_safe());
rcl_reset_error();
return NULL;
}
rcl_ret_t ret_clock = rcl_clock_fini(clock);
PyMem_Free(clock);
if (ret_clock != RCL_RET_OK) {
PyErr_Format(PyExc_RuntimeError,
"Failed to fini 'rcl_clock_t': %s", rcl_get_error_string_safe());
rcl_reset_error();
return NULL;
}

ret = rcl_timer_fini(timer);
PyMem_Free(timer);
PyMem_Free(clock);
} else if (PyCapsule_IsValid(pyentity, "rcl_guard_condition_t")) {
rcl_guard_condition_t * guard_condition = (rcl_guard_condition_t *)PyCapsule_GetPointer(
pyentity, "rcl_guard_condition_t");
Expand Down

0 comments on commit c788ec0

Please sign in to comment.