Close handle on error exits to avoid leaking handle

This commit is contained in:
John Lambert
2021-10-08 16:00:10 -07:00
committed by GitHub
parent f3b7c59639
commit 6015d9560e
+6 -1
View File
@@ -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;
}
}