https://github.com/python/cpython/commit/e471712958515b65b737ac742b294acf7de9220c
commit: e471712958515b65b737ac742b294acf7de9220c
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-07-02T17:19:42+03:00
summary:

gh-144067: Document terminal leak when initscr() follows setupterm() (GH-152624)

The curses library keeps a single current terminal: calling initscr()
or newterm() after setupterm() abandons the terminal that setupterm()
allocated without freeing it.  This cannot be fixed safely in code
(freeing the terminal would break the capsule API and pending terminfo
queries), so document the behavior, with a cross-reference from
initscr() and newterm().

Co-authored-by: Claude Opus 4.8 <[email protected]>

files:
M Doc/library/curses.rst

diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst
index bbe29e5f46ed1d..e413cd9d2bef2d 100644
--- a/Doc/library/curses.rst
+++ b/Doc/library/curses.rst
@@ -76,6 +76,8 @@ Initialization and termination
    Initialize the library. Return a :ref:`window <curses-window-objects>` 
object
    which represents the whole screen.
 
+   See :func:`setupterm` for a caveat about calling it before this function.
+
    .. note::
 
       If there is an error opening the terminal, the underlying curses library 
may
@@ -106,6 +108,8 @@ Initialization and termination
    The new screen becomes the current one.
    Use :func:`set_term` to switch between screens.
 
+   See :func:`setupterm` for a caveat about calling it before this function.
+
    .. versionadded:: next
 
 .. function:: new_prescr()
@@ -959,6 +963,13 @@ Terminfo database
    terminfo database entry could not be read.  If the terminal has already
    been initialized, this function has no effect.
 
+   .. note::
+
+      Calling :func:`initscr` or :func:`newterm` after :func:`setupterm`
+      leaks the terminal that :func:`setupterm` allocated:
+      the curses library keeps only a single current terminal
+      and does not free the previously allocated one.
+
 .. function:: tigetflag(capname)
 
    Return the value of the Boolean capability corresponding to the terminfo

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to