Use Marshal.ZeroFreeCoTaskMemUnicode

This removes the ClrFacade function of the same name as this API is in
.NET Core 1.0 Marhsal class, not SecureStringMarshal.
This commit is contained in:
Andrew Schwartzmeyer 2016-06-27 10:15:11 -07:00
parent 8be714ff68
commit 2f892e8127
11 changed files with 14 additions and 26 deletions

View File

@ -192,7 +192,7 @@ namespace Microsoft.PackageManagement.Provider.Utility
#if !CORECLR
Marshal.ZeroFreeGlobalAllocUnicode(value);
#else
SecureStringMarshal.ZeroFreeCoTaskMemUnicode(value);
Marshal.ZeroFreeCoTaskMemUnicode(value);
#endif
}
}
@ -250,4 +250,4 @@ namespace Microsoft.PackageManagement.Provider.Utility
}
}
}
}

View File

@ -96,7 +96,7 @@ namespace Microsoft.PowerShell.Cim
}
finally
{
ClrFacade.ZeroFreeCoTaskMemUnicode(plainTextString);
Marshal.ZeroFreeCoTaskMemUnicode(plainTextString);
}
}

View File

@ -2574,7 +2574,7 @@ namespace Microsoft.PowerShell.Commands
{
if (password != IntPtr.Zero)
{
ClrFacade.ZeroFreeCoTaskMemUnicode(password);
Marshal.ZeroFreeCoTaskMemUnicode(password);
}
}
}//end of if

View File

@ -2230,7 +2230,7 @@ namespace Microsoft.PowerShell.Commands
{
if (IntPtr.Zero != password)
{
ClrFacade.ZeroFreeCoTaskMemUnicode(password);
Marshal.ZeroFreeCoTaskMemUnicode(password);
}
if (IntPtr.Zero != hService)

View File

@ -160,7 +160,7 @@ namespace System.Management.Automation.SecurityAccountsManager.Extensions
#if CORECLR
IntPtr buffer = SecureStringMarshal.SecureStringToCoTaskMemUnicode(str);
string clear = Marshal.PtrToStringUni(buffer);
SecureStringMarshal.ZeroFreeCoTaskMemUnicode(buffer);
Marshal.ZeroFreeCoTaskMemUnicode(buffer);
#else
var bstr = Marshal.SecureStringToBSTR(str);
string clear = Marshal.PtrToStringAuto(bstr);
@ -200,4 +200,4 @@ namespace System.Management.Automation.SecurityAccountsManager.Extensions
return ex.MakeErrorRecord(ex.ErrorName, ex.ErrorCategory, target ?? ex.Target);
}
}
}
}

View File

@ -9,6 +9,7 @@ using System.Net;
using System.Security;
using SafeString=System.String;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using Microsoft.PowerShell;
@ -286,7 +287,7 @@ namespace System.Management.Automation
{
if (unmanagedPtr != IntPtr.Zero)
{
ClrFacade.ZeroFreeCoTaskMemUnicode(unmanagedPtr);
Marshal.ZeroFreeCoTaskMemUnicode(unmanagedPtr);
}
}
#else

View File

@ -179,7 +179,7 @@ namespace System.Management.Automation
{
if (p != IntPtr.Zero)
{
ClrFacade.ZeroFreeCoTaskMemUnicode(p);
Marshal.ZeroFreeCoTaskMemUnicode(p);
}
}

View File

@ -379,7 +379,7 @@ namespace System.Management.Automation.Remoting.Client
{
if (cred.password != IntPtr.Zero)
{
ClrFacade.ZeroFreeCoTaskMemUnicode(cred.password);
Marshal.ZeroFreeCoTaskMemUnicode(cred.password);
cred.password = IntPtr.Zero;
}

View File

@ -94,7 +94,7 @@ namespace Microsoft.PowerShell
}
finally
{
ClrFacade.ZeroFreeCoTaskMemUnicode(ptr);
Marshal.ZeroFreeCoTaskMemUnicode(ptr);
}
}

View File

@ -148,7 +148,7 @@ namespace System.Management.Automation
{
if (unmanagedMemory != IntPtr.Zero)
{
ZeroFreeCoTaskMemUnicode(unmanagedMemory);
Marshal.ZeroFreeCoTaskMemUnicode(unmanagedMemory);
}
}
return passwordInClearText;
@ -213,19 +213,6 @@ namespace System.Management.Automation
#endif
}
/// <summary>
/// Needed to pair with the SecureStringToCoTaskMemUnicode method which is member of
/// 'SecureStringMarshal' on CORE CLR, and member of 'Marshal' on Full CLR.
/// </summary>
internal static void ZeroFreeCoTaskMemUnicode(IntPtr unmanagedStr)
{
#if CORECLR
SecureStringMarshal.ZeroFreeCoTaskMemUnicode(unmanagedStr);
#else
Marshal.ZeroFreeCoTaskMemUnicode(unmanagedStr);
#endif
}
/// <summary>
/// Facade for SecureStringToCoTaskMemUnicode
/// </summary>

View File

@ -1023,7 +1023,7 @@ namespace System.Management.Automation.Internal
{
data[i] = Marshal.ReadByte(ptr, i);
}
ClrFacade.ZeroFreeCoTaskMemUnicode(ptr);
Marshal.ZeroFreeCoTaskMemUnicode(ptr);
try
{