Skip to content

Commit

Permalink
close CloseableNamedTemporaryFile before removing
Browse files Browse the repository at this point in the history
  • Loading branch information
blattm committed Dec 7, 2023
1 parent f81eddf commit 68115dd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions decompiler/util/closeable_named_temporary_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ def CloseableNamedTemporaryFile(**kwargs):
try:
yield file
finally:
# Close the file to be sure that it can be removed.
# It's ok if the file was already closed because NamedTemporaryFile's close method is idempotent.
file.close()
# If file was already deleted outside of this contextmanager, this will crash
# (just like the original NamedTemporaryFile).
# On NT, this might also crash if another handle to this file is still open
os.remove(file.name)

0 comments on commit 68115dd

Please sign in to comment.