Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit 32bc9a5

Browse files
committed
#317 Dispose WindowsIdentity
1 parent c328e22 commit 32bc9a5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Microsoft.AspNetCore.Server.HttpSys/RequestProcessing/NativeRequestContext.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,14 @@ internal WindowsPrincipal GetUser()
224224
&& info->InfoType == HttpApi.HTTP_REQUEST_INFO_TYPE.HttpRequestInfoTypeAuth
225225
&& info->pInfo->AuthStatus == HttpApi.HTTP_AUTH_STATUS.HttpAuthStatusSuccess)
226226
{
227-
return new WindowsPrincipal(new WindowsIdentity(info->pInfo->AccessToken,
228-
GetAuthTypeFromRequest(info->pInfo->AuthType).ToString()));
227+
// Duplicates AccessToken
228+
var identity = new WindowsIdentity(info->pInfo->AccessToken,
229+
GetAuthTypeFromRequest(info->pInfo->AuthType).ToString());
230+
231+
// Close the original
232+
UnsafeNclNativeMethods.SafeNetHandles.CloseHandle(info->pInfo->AccessToken);
233+
234+
return new WindowsPrincipal(identity);
229235
}
230236
}
231237

src/Microsoft.AspNetCore.Server.HttpSys/RequestProcessing/Request.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ internal void Dispose()
302302
// TODO: Verbose log
303303
_isDisposed = true;
304304
_nativeRequestContext.Dispose();
305+
(User?.Identity as WindowsIdentity)?.Dispose();
305306
if (_nativeStream != null)
306307
{
307308
_nativeStream.Dispose();

0 commit comments

Comments
 (0)