Skip to content

fix(diff_ifex): clean up temp files; fix stable_order_file return path - #173

Open
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:fix/diff-ifex-tempfile-leak
Open

fix(diff_ifex): clean up temp files; fix stable_order_file return path#173
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:fix/diff-ifex-tempfile-leak

Conversation

@SoundMatt

Copy link
Copy Markdown
Contributor

Two fixes in helpers/ifex/diff_ifex.py:

  1. stable_order_file returned from inside the with NamedTemporaryFile block, causing the file to be closed by the context manager while still referenced by the return value — but more importantly the fallthrough return None was dead code. Refactor: capture the name before exiting the with-block, then return after.

  2. compare_yaml_files created two temp files but never deleted them, leaking one or two files per invocation. Wrap the diff call in try/finally and unlink both files on exit (ignoring OSError in case a file was already removed).

Two fixes in the diff helper:

1. `stable_order_file` returned inside a `with tempfile.NamedTemporaryFile`
   block, which closed the context manager correctly but the `return` was
   unreachable once the with-block exited naturally.  Refactor to capture
   the temp-file name and return it after the with-block closes the file.

2. `compare_yaml_files` left the two temp files on disk after running.
   Wrap the diff call in try/finally and unlink both files on exit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
@gunnar-mb

Copy link
Copy Markdown
Collaborator

Good. Let's make sure the case is covered by unit tests before/after merging the code.

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