Description
Bug report
Bug description:
In _cursesmodule.c
, we have
#define SetDictInt(string,ch) \
do { \
PyObject *o = PyLong_FromLong((long) (ch)); \
if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
Py_DECREF(o); \
} \
} while (0)
However, PyDict_SetItemString
does not steal a reference. If the dict insertion fails for whatever reason, o
must be decref, which is not the case here. Similarly, in PyInit__curses
, a module object is explicitly created via PyModule_Create
but is not decref if an error occurs:
cpython/Modules/_cursesmodule.c
Line 4766 in b178bee
There are also calls that are not checked against errors:
cpython/Modules/_cursesmodule.c
Lines 4808 to 4811 in b178bee
Here, insertion is assumed to always succeed, but this may not be the case, in which case we shouldn't continue.
On the other hand, the PyCursesWindowType
leaks since it's never cleared. While it does not matter if you exit the interpreter, I think it may matter if you just want to unload the module and continue with a normal execution.
There are also other bugs that are more generally related to error-handling where some pointers might be NULL but are used as if they were not NULL, e.g. #123913).
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Projects
Status