From 4cfa3db255a38d3381060ceb6e1b4aa7e8106fdb Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 28 Jun 2018 19:38:29 -0400 Subject: [PATCH] Fix handle double-free in recently added WindowsIdentity test (dotnet/corefx#30731) Commit migrated from https://github.com/dotnet/corefx/commit/e36eaec682d5fa81bc1754e89787b0353b9c46b8 --- .../tests/WindowsIdentityTests.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Security.Principal.Windows/tests/WindowsIdentityTests.cs b/src/libraries/System.Security.Principal.Windows/tests/WindowsIdentityTests.cs index 144fccc..d019207 100644 --- a/src/libraries/System.Security.Principal.Windows/tests/WindowsIdentityTests.cs +++ b/src/libraries/System.Security.Principal.Windows/tests/WindowsIdentityTests.cs @@ -129,12 +129,16 @@ public class WindowsIdentityTests { using (var mutex = new Mutex()) { - Assert.Throws(() => + SafeAccessTokenHandle handle = null; + try { - WindowsIdentity.RunImpersonated( - new SafeAccessTokenHandle(mutex.SafeWaitHandle.DangerousGetHandle()), - () => { }); - }); + handle = new SafeAccessTokenHandle(mutex.SafeWaitHandle.DangerousGetHandle()); + Assert.Throws(() => WindowsIdentity.RunImpersonated(handle, () => { })); + } + finally + { + handle?.SetHandleAsInvalid(); + } } } -- 2.7.4