gh-155875: Fix new_prescr screen lifetime by BHUVANSH855 · Pull Request #155914 · python/cpython · GitHub
Skip to content

gh-155875: Fix new_prescr screen lifetime - #155914

Merged
serhiy-storchaka merged 4 commits into
python:mainfrom
BHUVANSH855:fix-155875-new-prescr-lifetime
Sep 15, 2026
Merged

serhiy-storchaka merged 4 commits into
python:mainfrom
BHUVANSH855:fix-155875-new-prescr-lifetime

Conversation

@BHUVANSH855

Copy link
Copy Markdown
Contributor

Summary

Fixes a use-after-free when curses.new_prescr() is followed by initscr() or newterm().

The pending pre-screen is now tracked by the curses module and its ownership is transferred when the screen is adopted, preventing the new_prescr() wrapper from deleting a live SCREEN.

Fixes issue gh-155875

@serhiy-storchaka

Copy link
Copy Markdown
Member

@serhiy-storchaka

Copy link
Copy Markdown
Member

Thanks, the ownership is right now, and it is clean under -R 3:3.

One thing left: test_initscr_after_new_prescr_keeps_screen_alive still runs initscr() on the real stdout, so its escape sequences end up in the test output. Redirect fd 1 to a pty for the duration of the test:

        s = self.make_pty()
        saved = os.dup(1)
        self.addCleanup(os.close, saved)
        self.addCleanup(os.dup2, saved, 1)
        os.dup2(s, 1)

With that it can be merged.

@BHUVANSH855

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) September 15, 2026 11:24
@serhiy-storchaka
serhiy-storchaka merged commit 0fc5ebc into python:main Sep 15, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants