From 68115ddda72537582a00333cffa058b9aa5f009e Mon Sep 17 00:00:00 2001 From: Manuel Blatt Date: Thu, 7 Dec 2023 12:57:47 +0100 Subject: [PATCH] close CloseableNamedTemporaryFile before removing --- decompiler/util/closeable_named_temporary_file.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/decompiler/util/closeable_named_temporary_file.py b/decompiler/util/closeable_named_temporary_file.py index a8ac2f8cb..90491e4ad 100644 --- a/decompiler/util/closeable_named_temporary_file.py +++ b/decompiler/util/closeable_named_temporary_file.py @@ -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)