summaryrefslogtreecommitdiffstats
path: root/Modules/_curses_panel.c
diff options
context:
space:
mode:
authorAndrew Kuchling <amk@amk.ca>2013-06-22 18:50:56 (GMT)
committerAndrew Kuchling <amk@amk.ca>2013-06-22 18:50:56 (GMT)
commit9290dd14b02508a667165d2e98f3f99aad61764e (patch)
treee17a24c10d220b6e3013ec00ebbe44aaf8efe75b /Modules/_curses_panel.c
parent45d9493ee9f91dcdf2bafdf67f3d5adc432848bf (diff)
downloadcpython-9290dd14b02508a667165d2e98f3f99aad61764e.zip
cpython-9290dd14b02508a667165d2e98f3f99aad61764e.tar.gz
cpython-9290dd14b02508a667165d2e98f3f99aad61764e.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/_curses_panel.c')
-rw-r--r--Modules/_curses_panel.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
index c11f3d8..f560702 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 *