X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fpython.c;h=6be727efb1305601a853bb6c16a4e281dc845ba2;hb=6c6314c7ccca4dae0b9233061dbdf36040dadffe;hp=d193d2d127574713e75e9d2c1db6633f48243d1c;hpb=f7cf0dad2e933ac6066ca5f27645ee577f065710;p=collectd.git diff --git a/src/python.c b/src/python.c index d193d2d1..6be727ef 100644 --- a/src/python.c +++ b/src/python.c @@ -371,6 +371,7 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li } if (PyErr_Occurred() != NULL) { cpy_log_exception("value building for write callback"); + Py_DECREF(list); CPY_RETURN_FROM_THREADS 0; } } @@ -419,16 +420,15 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li if (meta_data_get_boolean(meta, table[i], &b)) continue; if (b) - temp = Py_True; + PyDict_SetItemString(dict, table[i], Py_True); else - temp = Py_False; - PyDict_SetItemString(dict, table[i], temp); + PyDict_SetItemString(dict, table[i], Py_False); } free(table[i]); } free(table); } - v = PyObject_New(Values, (void *) &ValuesType); + v = PyObject_New(Values, (void *) &ValuesType); /* New reference. */ sstrncpy(v->data.host, value_list->host, sizeof(v->data.host)); sstrncpy(v->data.type, value_list->type, sizeof(v->data.type)); sstrncpy(v->data.type_instance, value_list->type_instance, sizeof(v->data.type_instance)); @@ -439,6 +439,7 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li v->values = list; v->meta = dict; ret = PyObject_CallFunctionObjArgs(c->callback, v, c->data, (void *) 0); /* New reference. */ + Py_XDECREF(v); if (ret == NULL) { cpy_log_exception("write callback"); } else { @@ -454,7 +455,7 @@ static int cpy_notification_callback(const notification_t *notification, user_da Notification *n; CPY_LOCK_THREADS - n = PyObject_New(Notification, (void *) &NotificationType); + n = PyObject_New(Notification, (void *) &NotificationType); /* New reference. */ sstrncpy(n->data.host, notification->host, sizeof(n->data.host)); sstrncpy(n->data.type, notification->type, sizeof(n->data.type)); sstrncpy(n->data.type_instance, notification->type_instance, sizeof(n->data.type_instance)); @@ -464,6 +465,7 @@ static int cpy_notification_callback(const notification_t *notification, user_da sstrncpy(n->message, notification->message, sizeof(n->message)); n->severity = notification->severity; ret = PyObject_CallFunctionObjArgs(c->callback, n, c->data, (void *) 0); /* New reference. */ + Py_XDECREF(n); if (ret == NULL) { cpy_log_exception("notification callback"); } else { @@ -623,7 +625,8 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwd user_data->data = c; ts.tv_sec = interval; ts.tv_nsec = (interval - ts.tv_sec) * 1000000000; - plugin_register_complex_read(buf, cpy_read_callback, &ts, user_data); + plugin_register_complex_read(/* group = */ NULL, buf, + cpy_read_callback, &ts, user_data); return cpy_string_to_unicode_or_bytes(buf); } @@ -896,6 +899,11 @@ static int cpy_init(void) { static pthread_t thread; sigset_t sigset; + if (!Py_IsInitialized()) { + WARNING("python: Plugin loaded but not configured."); + plugin_unregister_shutdown("python"); + return 0; + } PyEval_InitThreads(); /* Now it's finally OK to use python threads. */ for (c = cpy_init_callbacks; c; c = c->next) {