Repository navigation
Clean temporary output after fdopen setup failure - #241
Merged
stefankoegl merged 1 commit intoOct 26, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrowly scoped cleanup preserves existing fallback behavior and has targeted regression coverage with no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes a temporary-resource leak in the in-place CLI when mkstemp succeeds but os.fdopen fails, complementing the write-error cleanup in #235.
Changes:
- Closes the temporary descriptor and attempts to remove the temporary file before entering the existing fallback.
- Preserves best-effort cleanup and backup behavior.
- Adds regression coverage for descriptor closure, patched output, backups, and temporary-file removal.
| File | Description |
|---|---|
| tests.py | Tests fdopen failure cleanup with and without backups. |
| jsonpatch_cli.py | Cleans up temporary resources before falling back to direct output. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If mkstemp succeeds but os.fdopen raises OSError, the in-place CLI falls back to direct output while leaving the temporary descriptor and file behind. Close the descriptor and remove that temporary file before entering the existing fallback. Cleanup errors remain best effort, and the existing backup behavior is preserved.
A regression uses a real mkstemp descriptor and injects fdopen failure, with and without backups. Both subcases fail on the unchanged base. After the fix they verify the descriptor is closed, the patch is written, backups contain the original, and no temporary file remains.
Validation on native Windows / Python 3.12:
This covers output setup before the write/close cleanup in #235. AI assistance: OpenAI Codex investigated, implemented, tested and drafted this change at the account owner's request for further useful contributions. No separate human code review is claimed.