diff options
author | Andrew Kuchling <amk@amk.ca> | 2013-06-22 16:33:05 (GMT) |
---|---|---|
committer | Andrew Kuchling <amk@amk.ca> | 2013-06-22 16:33:05 (GMT) |
commit | aa6c297316a62baed42f10508cf21d781b0fbee4 (patch) | |
tree | 992a09204b27e988360e928a838056823d15684d /Modules | |
parent | 22b4b4cef4a4ed290d4c4941674f4e472f6bc3dc (diff) | |
download | cpython-aa6c297316a62baed42f10508cf21d781b0fbee4.zip cpython-aa6c297316a62baed42f10508cf21d781b0fbee4.tar.gz cpython-aa6c297316a62baed42f10508cf21d781b0fbee4.tar.bz2 |
#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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_curses_panel.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c index dd231e7..bdd5cf0 100644 --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -294,12 +294,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 * |