From 3260ece5c3c3e567ee19b952d7f95c84adbc24ae Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 18 Oct 2009 13:30:34 +0200 Subject: [PATCH] fix memory leak in new exception raising code --- Cython/Compiler/Nodes.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index ee49fe37..c8deaf6b 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -5061,7 +5061,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { } value = type; type = (PyObject*) Py_TYPE(value); - Py_INCREF(type); } else if (!PyExceptionClass_Check(type)) { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); @@ -5072,19 +5071,18 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { if (tb) { PyThreadState *tstate = PyThreadState_GET(); - value = tstate->curexc_value; - type = tstate->curexc_type; - Py_INCREF(type); - Py_XINCREF(value); - Py_INCREF(tb); - if (!value || value == Py_None) { - PyErr_NormalizeException(&type, &value, &tb); - } - if (value) { - PyException_SetTraceback(value, tb); - __Pyx_ErrRestore(type, value, tb); + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + value = tstate->curexc_value; + if (value && value != Py_None) { + PyException_SetTraceback(value, tb); + } + Py_XDECREF(tmp_tb); } } + bad: return; } -- 2.26.2