diff --git a/Misc/NEWS.d/next/Library/2026-01-20-20-13-35.gh-issue-144067.5YEhzs.rst b/Misc/NEWS.d/next/Library/2026-01-20-20-13-35.gh-issue-144067.5YEhzs.rst new file mode 100644 index 00000000000000..3964f0c7f7b002 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-01-20-20-13-35.gh-issue-144067.5YEhzs.rst @@ -0,0 +1,2 @@ +Fix a memory leak in the curses module when setupterm() is called before +initscr(), where the previously allocated terminal state was not freed. diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 61464348d6fab8..cef2ece3832225 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -3731,7 +3731,10 @@ _curses_initscr_impl(PyObject *module) } return PyCursesWindow_New(state, stdscr, NULL, NULL); } - + if (cur_term != NULL) { + del_curterm(cur_term); + cur_term = NULL; + } win = initscr(); if (win == NULL) {