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:
parent
ca09adf316
commit
790fa44735
1 changed files with 8 additions and 6 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue