[mod_python] Fix PyObject leaks in eval_some_python function
This commit is contained in:
parent
212c1ec8d5
commit
bc8e3da74c
|
@ -177,7 +177,7 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
|
|||
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;
|
||||
|
@ -248,15 +248,15 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
|
|||
}
|
||||
|
||||
// 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);
|
||||
|
@ -285,6 +285,7 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
|
|||
if (stream) {
|
||||
stp = mod_python_conjure_stream(stream);
|
||||
if (stream->param_event) {
|
||||
Py_XDECREF(eve);
|
||||
eve = mod_python_conjure_event(stream->param_event);
|
||||
}
|
||||
}
|
||||
|
@ -304,7 +305,6 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
|
|||
// 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
|
||||
|
@ -323,13 +323,15 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
|
|||
|
||||
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
|
||||
|
@ -342,8 +344,6 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
|
|||
|
||||
switch_safe_free(dupargs);
|
||||
switch_safe_free(script);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue