diff options
author | Andrew Kuchling <amk@amk.ca> | 2013-06-22 14:50:56 -0400 |
---|---|---|
committer | Andrew Kuchling <amk@amk.ca> | 2013-06-22 14:50:56 -0400 |
commit | 4905e1200b1634d5d9ee2503f9a6e381e873df6b (patch) | |
tree | 2507c57e4c6cd946ef9b5a24a46ab229ca5e43a7 /Modules/_curses_panel.c | |
parent | 71b556615d88a19d584e172c78a5ca0434e4ad61 (diff) | |
download | cpython-4905e1200b1634d5d9ee2503f9a6e381e873df6b.tar.gz |
#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/_curses_panel.c')
-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 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 * |