mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
#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.
This commit is contained in:
parent
45d9493ee9
commit
9290dd14b0
2 changed files with 18 additions and 4 deletions
|
@ -323,12 +323,17 @@ static PyObject *
|
|||
PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj)
|
||||
{
|
||||
PyObject *oldobj;
|
||||
int rc;
|
||||
PyCursesInitialised;
|
||||
oldobj = (PyObject *) panel_userptr(self->pan);
|
||||
Py_XDECREF(oldobj);
|
||||
Py_INCREF(obj);
|
||||
return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj),
|
||||
"set_panel_userptr");
|
||||
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);
|
||||
return PyCursesCheckERR(rc, "set_panel_userptr");
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue