From 4905e1200b1634d5d9ee2503f9a6e381e873df6b Mon Sep 17 00:00:00 2001 From: Andrew Kuchling Date: Sat, 22 Jun 2013 14:50:56 -0400 Subject: #18113: avoid segfault if Py_XDECREF triggers code that calls set_panel_userptr again Problem noted & original patch by Serhiy Storchaka; I tweaked the patch a bit. --- Modules/_curses_panel.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Modules/_curses_panel.c') diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c index c11f3d8476..f560702878 100644 --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -323,12 +323,17 @@ static PyObject * PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj) { PyObject *oldobj; + int rc; PyCursesInitialised; + Py_INCREF(obj); oldobj = (PyObject *) panel_userptr(self->pan); + rc = set_panel_userptr(self->pan, (void*)obj); + if (rc == ERR) { + /* In case of an ncurses error, decref the new object again */ + Py_DECREF(obj); + } Py_XDECREF(oldobj); - Py_INCREF(obj); - return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj), - "set_panel_userptr"); + return PyCursesCheckERR(rc, "set_panel_userptr"); } static PyObject * -- cgit v1.2.1