char *argv[2] = { 0 };
int argc;
char *script = NULL;
- PyObject *module = NULL, *sp = NULL, *stp = NULL, *eve = NULL;
+ PyObject *module_o = NULL, *module = NULL, *sp = NULL, *stp = NULL, *eve = NULL;
PyObject *function = NULL;
PyObject *arg = NULL;
PyObject *result = NULL;
}
// import the module
- module = PyImport_ImportModule((char *) script);
- if (!module) {
+ module_o = PyImport_ImportModule((char *) script);
+ if (!module_o) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error importing module\n");
print_python_error(script);
PyErr_Clear();
goto done_swap_out;
}
// reload the module
- module = PyImport_ReloadModule(module);
+ module = PyImport_ReloadModule(module_o);
if (!module) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error reloading module\n");
print_python_error(script);
if (stream) {
stp = mod_python_conjure_stream(stream);
if (stream->param_event) {
+ Py_XDECREF(eve);
eve = mod_python_conjure_event(stream->param_event);
}
}
// invoke the handler
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call python script \n");
result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *) NULL);
- Py_DECREF(function);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished calling python script \n");
// check the result and print out any errors
done_swap_out:
- if (arg) {
- Py_DECREF(arg);
- }
- if (sp) {
- Py_DECREF(sp);
- }
+ Py_XDECREF(result);
+ Py_XDECREF(arg);
+ Py_XDECREF(function);
+ Py_XDECREF(module);
+ Py_XDECREF(module_o);
+ Py_XDECREF(stp);
+ Py_XDECREF(eve);
+ Py_XDECREF(sp);
if (tstate) {
// thread state must be cleared explicitly or we'll get memory leaks
switch_safe_free(dupargs);
switch_safe_free(script);
-
-
}