NLog / NLog.WindowsIdentity

NLog extensions for displaying User Windows Identity and target wrapper for user impersonation
BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link

WindowsIdentityLayoutRenderer not disposing WindowsIdentity #11

Closed 11v1 closed 2 years ago

11v1 commented 2 years ago

Hi!

I think WindowsIdentityLayoutRenderer should dispose WindowsIdentity instance in Append method.

NLog version: 4.7.15

Platform: .Net 4.5

welcome[bot] commented 2 years ago

Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!

snakefoot commented 2 years ago

Yes always wondered why it was never diposed, since it would leak SafeHandles, that would fill the finalizer queue.

WindowsIdentity.GetCurrent() returns an instance which you should dispose, otherwise you temporarily leak a user handle. (Its a safehandle so its not a huge deal). Infact, most times you use WindowsIdentity it is good to dispose of the item. Except for one case.

If you call Impersonate() on a WindowsIdentity instance, disposing it will cause hard to diagnose crashes.

Have now created NLog/NLog#4867