Overview
| Artifact ID: | a2cbf3d7db221604d663dba6540a953d19c570f636bf70e0bbe5b8d02bde98d0 |
|---|---|
| Ticket: | 91c9bc1c457fda269ae18595944fc3c2b54d961d
Standard channels (stdin, stdout, stderr) on Windows may get broken by dup2() |
| User & Date: | serhiy.storchaka on 2026-11-12 20:29:57 |
Changes
- closer changed to: "nobody"
- foundin changed to: "8.6.18, 9.0.5, 9.1.1"
- icomment:
Reopening: this is reported again for tkinter in [https://github.com/python/cpython/issues/161620|python/cpython#161620] (pytest --capture=fd), and calling Tcl_SetStdChannel() is not possible there, because tkinter does not know about the dup2(). Reproduced on Windows 11 with 8.6 and trunk. When stdout is a disk file, dup2() on fd 1 closes the handle that Tcl's stdout channel still has. The next CreateFile() in open gets the same handle value, and OpenFileChannel() finds the stale stdout channel by that value: open fails with an empty error message, and the new handle leaks. Reproducers in C and Python are attached (run them with stdout redirected to a file). Proposed fix in branch [/timeline?r=win-open-stale-handle|win-open-stale-handle]: only Tcl_MakeFileChannel() looks for an existing channel with the same handle. A handle just returned by CreateFile() cannot belong to a live channel.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "None"
- status changed to: "Open"