From 6015d9560ef0377fd0f307cd3078e5948f769353 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Fri, 8 Oct 2021 16:00:10 -0700 Subject: [PATCH] Close handle on error exits to avoid leaking handle --- DarkLoadLibrary/src/darkloadlibrary.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DarkLoadLibrary/src/darkloadlibrary.c b/DarkLoadLibrary/src/darkloadlibrary.c index 4b18c5a..cf6a43f 100644 --- a/DarkLoadLibrary/src/darkloadlibrary.c +++ b/DarkLoadLibrary/src/darkloadlibrary.c @@ -119,6 +119,7 @@ BOOL ReadFileToBuffer( if (dwSize == INVALID_FILE_SIZE) { pdModule->ErrorMsg = L"Failed to get DLL file size"; + pCloseHandle(hFile); return FALSE; } @@ -132,6 +133,7 @@ BOOL ReadFileToBuffer( if (pdModule->pbDllData == NULL) { pdModule->ErrorMsg = L"Failed to allocate memory for DLL data"; + pCloseHandle(hFile); return FALSE; } @@ -143,6 +145,9 @@ BOOL ReadFileToBuffer( NULL)) { pdModule->ErrorMsg = L"Failed to read data from DLL file"; + pCloseHandle(hFile); + // TODO: need to Free buffer on error: e.g. pVirtualFree(pdModule->pbDllData); + return FALSE; } @@ -305,4 +310,4 @@ BOOL ConcealLibrary( pdModule->ErrorMsg = L"Not implemented yet, sorry"; return FALSE; -} \ No newline at end of file +}