fix a bug introduced in last mod_python commit on greenlizard branch where dtmfs will segfault the switch due to an incorrect Py_XDECREF.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5626 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Traun Leyden 2007-08-20 16:43:42 +00:00
parent 4f58b28247
commit e9732b7c47

View File

@ -109,7 +109,7 @@ switch_status_t PySession::run_dtmf_callback(void *input,
PyObject *func, *arglist; PyObject *func, *arglist;
PyObject *pyresult; PyObject *pyresult;
PyObject* headerdict; PyObject *headerdict;
char *resultStr; char *resultStr;
char *funcargs; char *funcargs;
@ -159,6 +159,10 @@ switch_status_t PySession::run_dtmf_callback(void *input,
headerdict = PyDict_New(); headerdict = PyDict_New();
for (hp = event->headers; hp; hp = hp->next) { for (hp = event->headers; hp; hp = hp->next) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding event header to result"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding event header to result");
// TODO: create PyObject pointers for name and value
// and explicitly decref them. all ref counting stuff is
// a mess and needs to be tested and looked at closer.
PyDict_SetItem(headerdict, PyDict_SetItem(headerdict,
Py_BuildValue("s", hp->name), Py_BuildValue("s", hp->name),
Py_BuildValue("s", hp->value)); Py_BuildValue("s", hp->value));
@ -172,7 +176,9 @@ switch_status_t PySession::run_dtmf_callback(void *input,
"headers", "headers",
headerdict); headerdict);
//arglist = Py_BuildValue("(sis)", event->body, itype, funcargs); Py_XDECREF(headerdict);
} }
else { else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown input type: %d\n", itype); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown input type: %d\n", itype);
@ -189,10 +195,9 @@ switch_status_t PySession::run_dtmf_callback(void *input,
did_swap_in = end_allow_threads(); did_swap_in = end_allow_threads();
pyresult = PyEval_CallObject(func, arglist); pyresult = PyEval_CallObject(func, arglist);
Py_XDECREF(arglist); // Trash arglist Py_XDECREF(arglist); // Trash arglist
Py_XDECREF(headerdict);
if (pyresult && pyresult != Py_None) { if (pyresult && pyresult != Py_None) {
resultStr = (char *) PyString_AsString(pyresult); resultStr = (char *) PyString_AsString(pyresult);
@ -200,7 +205,7 @@ switch_status_t PySession::run_dtmf_callback(void *input,
return cbresult; return cbresult;
} }
else { else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Python callback\n returned None"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Python callback\n returned None");
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
} }