1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-11 02:13:38 +09:00

Dispose SafeHandle on error path (dotnet/corefx#30583)

Commit migrated from aff570af58
This commit is contained in:
Jan Kotas 2018-06-21 17:51:04 -07:00 committed by GitHub
parent ca09adf316
commit 790fa44735

View file

@ -703,15 +703,17 @@ namespace System.Diagnostics
// this is only a "pseudo handle" to the current process - no need to close it later
SafeProcessHandle processHandle = Interop.Kernel32.GetCurrentProcess();
// get the process token so we can adjust the privilege on it. We DO need to
// close the token when we're done with it.
if (!Interop.Advapi32.OpenProcessToken(processHandle, Interop.Kernel32.HandleOptions.TOKEN_ADJUST_PRIVILEGES, out SafeTokenHandle hToken))
{
throw new Win32Exception();
}
SafeTokenHandle hToken = null;
try
{
// get the process token so we can adjust the privilege on it. We DO need to
// close the token when we're done with it.
if (!Interop.Advapi32.OpenProcessToken(processHandle, Interop.Kernel32.HandleOptions.TOKEN_ADJUST_PRIVILEGES, out hToken))
{
throw new Win32Exception();
}
if (!Interop.Advapi32.LookupPrivilegeValue(null, privilegeName, out Interop.Advapi32.LUID luid))
{
throw new Win32Exception();