Better protection against leaking handles - use a nested try-finally when allocating inside a CER. The inner finally protects against the case where the PtrToStructure, which allocates, fails.
This commit is contained in:
@@ -30,8 +30,15 @@ namespace NSspi
|
||||
|
||||
if( status == SecurityStatus.OK && rawInfoPtr != IntPtr.Zero )
|
||||
{
|
||||
Marshal.PtrToStructure( rawInfoPtr, info );
|
||||
freeStatus = NativeMethods.FreeContextBuffer( rawInfoPtr );
|
||||
try
|
||||
{
|
||||
// This performs allocations as it makes room for the strings contained in the SecPkgInfo class.
|
||||
Marshal.PtrToStructure( rawInfoPtr, info );
|
||||
}
|
||||
finally
|
||||
{
|
||||
freeStatus = NativeMethods.FreeContextBuffer( rawInfoPtr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user