mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-17 01:02:12 +00:00
[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 };
|
char *argv[2] = { 0 };
|
||||||
int argc;
|
int argc;
|
||||||
char *script = NULL;
|
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 *function = NULL;
|
||||||
PyObject *arg = NULL;
|
PyObject *arg = NULL;
|
||||||
PyObject *result = NULL;
|
PyObject *result = NULL;
|
||||||
@ -248,15 +248,15 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// import the module
|
// import the module
|
||||||
module = PyImport_ImportModule((char *) script);
|
module_o = PyImport_ImportModule((char *) script);
|
||||||
if (!module) {
|
if (!module_o) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error importing module\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error importing module\n");
|
||||||
print_python_error(script);
|
print_python_error(script);
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
goto done_swap_out;
|
goto done_swap_out;
|
||||||
}
|
}
|
||||||
// reload the module
|
// reload the module
|
||||||
module = PyImport_ReloadModule(module);
|
module = PyImport_ReloadModule(module_o);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error reloading module\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error reloading module\n");
|
||||||
print_python_error(script);
|
print_python_error(script);
|
||||||
@ -285,6 +285,7 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
|
|||||||
if (stream) {
|
if (stream) {
|
||||||
stp = mod_python_conjure_stream(stream);
|
stp = mod_python_conjure_stream(stream);
|
||||||
if (stream->param_event) {
|
if (stream->param_event) {
|
||||||
|
Py_XDECREF(eve);
|
||||||
eve = mod_python_conjure_event(stream->param_event);
|
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
|
// invoke the handler
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call python script \n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call python script \n");
|
||||||
result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *) NULL);
|
result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *) NULL);
|
||||||
Py_DECREF(function);
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished calling python script \n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished calling python script \n");
|
||||||
|
|
||||||
// check the result and print out any errors
|
// 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:
|
done_swap_out:
|
||||||
|
|
||||||
if (arg) {
|
|
||||||
Py_DECREF(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sp) {
|
Py_XDECREF(result);
|
||||||
Py_DECREF(sp);
|
Py_XDECREF(arg);
|
||||||
}
|
Py_XDECREF(function);
|
||||||
|
Py_XDECREF(module);
|
||||||
|
Py_XDECREF(module_o);
|
||||||
|
Py_XDECREF(stp);
|
||||||
|
Py_XDECREF(eve);
|
||||||
|
Py_XDECREF(sp);
|
||||||
|
|
||||||
if (tstate) {
|
if (tstate) {
|
||||||
// thread state must be cleared explicitly or we'll get memory leaks
|
// 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(dupargs);
|
||||||
switch_safe_free(script);
|
switch_safe_free(script);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user