Skip to content

Comments

close mkstemp fd before reopening file in _tempfilepager#3222

Closed
bysiber wants to merge 1 commit intopallets:mainfrom
bysiber:fix-tempfilepager-fd-leak
Closed

close mkstemp fd before reopening file in _tempfilepager#3222
bysiber wants to merge 1 commit intopallets:mainfrom
bysiber:fix-tempfilepager-fd-leak

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

_tempfilepager creates a temporary file using tempfile.mkstemp(), which returns an open file descriptor. However, the file is then re-opened via open_stream(filename, "wb") for writing without closing the original fd first.

The original fd stays open for the duration of the write and the entire subprocess call, only being closed in the finally block. This is a resource leak and can cause issues on Windows where open file descriptors prevent other processes from accessing the file — the pager subprocess may not be able to read the temp file.

This moves the os.close(fd) call to immediately after mkstemp(), before the file is re-opened for writing.

@davidism davidism closed this Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants