X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fpython.c;h=6a65ff25c5de4dff9d17de281c3abbd269f33981;hb=3e413a72f2387d600fa00169823c7ce0d0b649b5;hp=0fb49d4caa95b737f90afb8ff08cedfbc3282003;hpb=cc0bb2b472628ccede974a02c822d1f9189f0d21;p=collectd.git diff --git a/src/python.c b/src/python.c index 0fb49d4c..6a65ff25 100644 --- a/src/python.c +++ b/src/python.c @@ -289,7 +289,7 @@ void cpy_log_exception(const char *context) { Py_XDECREF(traceback); return; } - list = PyObject_CallFunction(cpy_format_exception, "NNN", type, value, traceback); /* New reference. */ + list = PyObject_CallFunction(cpy_format_exception, "NNN", type, value, traceback); /* New reference. Steals references from "type", "value" and "traceback". */ if (list) l = PyObject_Length(list); for (i = 0; i < l; ++i) { @@ -309,9 +309,6 @@ void cpy_log_exception(const char *context) { } Py_XDECREF(list); PyErr_Clear(); - Py_DECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); } static int cpy_read_callback(user_data_t *data) { @@ -576,7 +573,7 @@ static PyObject *cpy_register_generic_userdata(void *reg, void *handler, PyObjec char buf[512]; reg_function_t *register_function = (reg_function_t *) reg; cpy_callback_t *c = NULL; - user_data_t *user_data = NULL; + user_data_t user_data; char *name = NULL; PyObject *callback = NULL, *data = NULL; static char *kwlist[] = {"callback", "data", "name", NULL}; @@ -597,17 +594,19 @@ static PyObject *cpy_register_generic_userdata(void *reg, void *handler, PyObjec c->callback = callback; c->data = data; c->next = NULL; - user_data = malloc(sizeof(*user_data)); - user_data->free_func = cpy_destroy_user_data; - user_data->data = c; - register_function(buf, handler, user_data); + + memset (&user_data, 0, sizeof (user_data)); + user_data.free_func = cpy_destroy_user_data; + user_data.data = c; + + register_function(buf, handler, &user_data); return cpy_string_to_unicode_or_bytes(buf); } static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwds) { char buf[512]; cpy_callback_t *c = NULL; - user_data_t *user_data = NULL; + user_data_t user_data; double interval = 0; char *name = NULL; PyObject *callback = NULL, *data = NULL; @@ -630,13 +629,16 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwd c->callback = callback; c->data = data; c->next = NULL; - user_data = malloc(sizeof(*user_data)); - user_data->free_func = cpy_destroy_user_data; - user_data->data = c; + + memset (&user_data, 0, sizeof (user_data)); + user_data.free_func = cpy_destroy_user_data; + user_data.data = c; + ts.tv_sec = interval; ts.tv_nsec = (interval - ts.tv_sec) * 1000000000; - plugin_register_complex_read(/* group = */ NULL, buf, - cpy_read_callback, &ts, user_data); + plugin_register_complex_read(/* group = */ "python", buf, + cpy_read_callback, &ts, &user_data); + return cpy_string_to_unicode_or_bytes(buf); } @@ -933,7 +935,7 @@ static int cpy_init(void) { pthread_sigmask(SIG_BLOCK, &sigset, NULL); state = PyEval_SaveThread(); if (do_interactive) { - if (pthread_create(&thread, NULL, cpy_interactive, NULL)) { + if (plugin_thread_create(&thread, NULL, cpy_interactive, NULL)) { ERROR("python: Error creating thread for interactive interpreter."); } }