diff --git a/src/python.c b/src/python.c index d81448d..0b0aa6f 100644 --- a/src/python.c +++ b/src/python.c @@ -3162,23 +3162,29 @@ pyconnection_x509_cb(void *udata, int islast, int nid, const char *field, static void pytimer_run(void *arg, u_int64_t now) { - PyObject *ret; - struct pytimer *timer = arg; + PyObject *ret; + struct pytimer *timer = arg; + struct kore_timer *run; + + run = timer->run; + timer->run = NULL; PyErr_Clear(); ret = PyObject_CallFunctionObjArgs(timer->callable, timer->udata, NULL); Py_XDECREF(ret); - Py_XDECREF(timer->udata); - timer->udata = NULL; kore_python_log_error("pytimer_run"); if (timer->flags & KORE_TIMER_ONESHOT) { - timer->run = NULL; + run->flags |= KORE_TIMER_ONESHOT; Py_DECREF((PyObject *)timer); } + else { + timer->run = run; + } } + static void pytimer_dealloc(struct pytimer *timer) { @@ -3192,28 +3198,25 @@ pytimer_dealloc(struct pytimer *timer) timer->callable = NULL; } - PyObject_Del((PyObject *)timer); -} - -static PyObject * -pytimer_close(struct pytimer *timer, PyObject *args) -{ - if (timer->run != NULL) { - kore_timer_remove(timer->run); - timer->run = NULL; - } - - if (timer->callable != NULL) { - Py_DECREF(timer->callable); - timer->callable = NULL; - } - if (timer->udata != NULL) { Py_DECREF(timer->udata); timer->udata = NULL; } - Py_INCREF((PyObject *)timer); + PyObject_Del((PyObject *)timer); +} + +static PyObject * +pytimer_close(struct pytimer *timer, PyObject *args) +{ + if (timer->run != NULL) { + kore_timer_remove(timer->run); + timer->run = NULL; + Py_DECREF((PyObject *)timer); + } else { + timer->flags |= KORE_TIMER_ONESHOT; + } + Py_RETURN_TRUE; }