VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Dlgcode.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-07-09 05:32:14 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-11-08 23:20:40 +0100
commit5281e2d3b9adea8dff1730d78fe94af85582aea8 (patch)
treeeaf094f9e339ff1809e2c18bb3e37e88450c6184 /src/Common/Dlgcode.c
parent2a288a7e127d37962fa0ec3659d73d8f33bfdc63 (diff)
downloadVeraCrypt-5281e2d3b9adea8dff1730d78fe94af85582aea8.tar.gz
VeraCrypt-5281e2d3b9adea8dff1730d78fe94af85582aea8.zip
Static Code Analysis : fix resource leakage by ensuring that all Windows handles are released properly
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r--src/Common/Dlgcode.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 54b848dc..f645fdec 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -1349,7 +1349,7 @@ HBITMAP RenderBitmap (char *resource, HWND hwndDest, int x, int y, int nWidth, i
HDC hdcDest = GetDC (hwndDest);
BitBlt (hdcDest, x, y, nWidth, nHeight, hdcRescaled, 0, 0, SRCCOPY);
- DeleteDC (hdcDest);
+ ReleaseDC (hwndDest, hdcDest);
}
else
{
@@ -3492,6 +3492,8 @@ load:
bPortableModeConfirmed = TRUE;
+ if (hDriver != INVALID_HANDLE_VALUE)
+ CloseHandle (hDriver);
hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
}
@@ -7484,16 +7486,19 @@ __int64 GetFileSize64 (const char *path)
{
HANDLE h = CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
LARGE_INTEGER size;
+ __int64 retSize = -1;
- if (h == INVALID_HANDLE_VALUE)
- return -1;
-
- if (GetFileSizeEx (h, &size) == 0)
- return -1;
+ if (h)
+ {
+ if (GetFileSizeEx (h, &size))
+ {
+ retSize = size.QuadPart;
+ }
- CloseHandle (h);
+ CloseHandle (h);
+ }
- return size.QuadPart;
+ return retSize;
}
@@ -8214,12 +8219,19 @@ BOOL RestartComputer (void)
AdjustTokenPrivileges (hTkn, false, &tokenPrivil, 0, (PTOKEN_PRIVILEGES) NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
+ {
+ CloseHandle(hTkn);
return false;
+ }
if (!ExitWindowsEx (EWX_REBOOT,
SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED))
+ {
+ CloseHandle(hTkn);
return false;
+ }
+ CloseHandle(hTkn);
return true;
}