From 1467a53e6071e1235b304bc75476df38cf5faa3b Mon Sep 17 00:00:00 2001 From: shreyamalviya Date: Mon, 14 Jun 2021 23:24:09 +0530 Subject: [PATCH] island: Use win32file.CloseHandle() to close file descriptor on Windows --- monkey/monkey_island/cc/environment/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/monkey/monkey_island/cc/environment/utils.py b/monkey/monkey_island/cc/environment/utils.py index 2f1b161e1..86370e01f 100644 --- a/monkey/monkey_island/cc/environment/utils.py +++ b/monkey/monkey_island/cc/environment/utils.py @@ -83,7 +83,7 @@ def _create_secure_file_windows(path: str): file_creation = win32file.CREATE_NEW # fails if file exists file_attributes = win32file.FILE_ATTRIBUTE_NORMAL - with win32file.CreateFile( + win32file.CloseHandle(win32file.CreateFile( path, file_access, file_sharing, @@ -93,8 +93,7 @@ def _create_secure_file_windows(path: str): win32job.CreateJobObject( None, "" ), # https://stackoverflow.com/questions/46800142/in-python-with-pywin32-win32job-the-createjobobject-function-how-do-i-pass-nu # noqa: E501 - ) as x: # noqa: F841 - pass + )) except Exception as ex: LOG.error(f'Could not create a file at "{path}": {str(ex)}')