From dce0bab626c28d7f88781c20a40293ecfb230fbe Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Sat, 29 Jul 2017 17:04:38 -0700 Subject: [PATCH] Clean up ClrFacade.cs - remove ClrFacade.DestroyStructure (#4378) --- .../LocalAccounts/Native.cs | 2 +- .../LocalAccounts/Sam.cs | 18 +++++++++--------- .../security/Authenticode.cs | 8 ++++---- .../security/nativeMethods.cs | 12 ++++++------ .../utils/ClrFacade.cs | 9 --------- 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Native.cs b/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Native.cs index 609320215d..607166b6f1 100644 --- a/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Native.cs +++ b/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Native.cs @@ -155,7 +155,7 @@ namespace System.Management.Automation.SecurityAccountsManager.Native { if (objectName != IntPtr.Zero) { - ClrFacade.DestroyStructure(objectName); + Marshal.DestroyStructure(objectName); Marshal.FreeHGlobal(objectName); objectName = IntPtr.Zero; } diff --git a/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Sam.cs b/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Sam.cs index cae1f50f95..84fbacd96e 100644 --- a/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Sam.cs +++ b/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Sam.cs @@ -1252,7 +1252,7 @@ namespace System.Management.Automation.SecurityAccountsManager out userHandle, out grantedAccess, out relativeId); - ClrFacade.DestroyStructure(buffer); + Marshal.DestroyStructure(buffer); Marshal.FreeHGlobal(buffer); buffer = IntPtr.Zero; ThrowOnFailure(status); @@ -1371,7 +1371,7 @@ namespace System.Management.Automation.SecurityAccountsManager { if (buffer != IntPtr.Zero) { - ClrFacade.DestroyStructure(buffer); + Marshal.DestroyStructure(buffer); Marshal.FreeHGlobal(buffer); } if (aliasHandle != IntPtr.Zero) @@ -1700,7 +1700,7 @@ namespace System.Management.Automation.SecurityAccountsManager status = SamApi.SamSetInformationUser(userHandle, USER_INFORMATION_CLASS.UserAllInformation, buffer); - ClrFacade.DestroyStructure(buffer); + Marshal.DestroyStructure(buffer); Marshal.FreeHGlobal(buffer); buffer = IntPtr.Zero; ThrowOnFailure(status); @@ -1760,7 +1760,7 @@ namespace System.Management.Automation.SecurityAccountsManager { if (buffer != IntPtr.Zero) { - ClrFacade.DestroyStructure(buffer); + Marshal.DestroyStructure(buffer); Marshal.FreeHGlobal(buffer); } if (userHandle != IntPtr.Zero) @@ -1903,7 +1903,7 @@ namespace System.Management.Automation.SecurityAccountsManager Win32.MAXIMUM_ALLOWED, out aliasHandle, out relativeId); - ClrFacade.DestroyStructure(buffer); + Marshal.DestroyStructure(buffer); Marshal.FreeHGlobal(buffer); buffer = IntPtr.Zero; ThrowOnFailure(status); @@ -1920,7 +1920,7 @@ namespace System.Management.Automation.SecurityAccountsManager ALIAS_INFORMATION_CLASS.AliasAdminCommentInformation, buffer); - ClrFacade.DestroyStructure(buffer); + Marshal.DestroyStructure(buffer); Marshal.FreeHGlobal(buffer); buffer = IntPtr.Zero; ThrowOnFailure(status); @@ -1995,7 +1995,7 @@ namespace System.Management.Automation.SecurityAccountsManager { if (buffer != IntPtr.Zero) { - ClrFacade.DestroyStructure(buffer); + Marshal.DestroyStructure(buffer); Marshal.FreeHGlobal(buffer); } if (aliasHandle != IntPtr.Zero) @@ -2268,7 +2268,7 @@ namespace System.Management.Automation.SecurityAccountsManager { if (buffer != IntPtr.Zero) { - ClrFacade.DestroyStructure(buffer); + Marshal.DestroyStructure(buffer); Marshal.FreeHGlobal(buffer); } } @@ -2612,7 +2612,7 @@ namespace System.Management.Automation.SecurityAccountsManager { if (buffer != IntPtr.Zero) { - ClrFacade.DestroyStructure(buffer); + Marshal.DestroyStructure(buffer); Marshal.FreeHGlobal(buffer); } } diff --git a/src/System.Management.Automation/security/Authenticode.cs b/src/System.Management.Automation/security/Authenticode.cs index 47e0364bce..c90cd1013a 100644 --- a/src/System.Management.Automation/security/Authenticode.cs +++ b/src/System.Management.Automation/security/Authenticode.cs @@ -216,7 +216,7 @@ namespace System.Management.Automation if (si.pSignExtInfo != null) { - ClrFacade.DestroyStructure(si.pSignExtInfo); + Marshal.DestroyStructure(si.pSignExtInfo); Marshal.FreeCoTaskMem(si.pSignExtInfo); } @@ -268,7 +268,7 @@ namespace System.Management.Automation } finally { - ClrFacade.DestroyStructure(pSignInfo); + Marshal.DestroyStructure(pSignInfo); Marshal.FreeCoTaskMem(pSignInfo); } @@ -552,9 +552,9 @@ namespace System.Management.Automation } finally { - ClrFacade.DestroyStructure(WINTRUST_ACTION_GENERIC_VERIFY_V2); + Marshal.DestroyStructure(WINTRUST_ACTION_GENERIC_VERIFY_V2); Marshal.FreeCoTaskMem(WINTRUST_ACTION_GENERIC_VERIFY_V2); - ClrFacade.DestroyStructure(wtdBuffer); + Marshal.DestroyStructure(wtdBuffer); Marshal.FreeCoTaskMem(wtdBuffer); } return dwResult; diff --git a/src/System.Management.Automation/security/nativeMethods.cs b/src/System.Management.Automation/security/nativeMethods.cs index 04878490a1..b19a9021be 100644 --- a/src/System.Management.Automation/security/nativeMethods.cs +++ b/src/System.Management.Automation/security/nativeMethods.cs @@ -1037,9 +1037,9 @@ namespace System.Management.Automation.Security } finally { - ClrFacade.DestroyStructure(wtdBuffer); + Marshal.DestroyStructure(wtdBuffer); Marshal.FreeCoTaskMem(wtdBuffer); - ClrFacade.DestroyStructure(WINTRUST_ACTION_GENERIC_VERIFY_V2); + Marshal.DestroyStructure(WINTRUST_ACTION_GENERIC_VERIFY_V2); Marshal.FreeCoTaskMem(WINTRUST_ACTION_GENERIC_VERIFY_V2); } @@ -1051,12 +1051,12 @@ namespace System.Management.Automation.Security (WINTRUST_BLOB_INFO)ClrFacade.PtrToStructure(wtd.Choice.pBlob); Marshal.FreeCoTaskMem(originalBlob.pbMemObject); - ClrFacade.DestroyStructure(wtd.Choice.pBlob); + Marshal.DestroyStructure(wtd.Choice.pBlob); Marshal.FreeCoTaskMem(wtd.Choice.pBlob); } else { - ClrFacade.DestroyStructure(wtd.Choice.pFile); + Marshal.DestroyStructure(wtd.Choice.pFile); Marshal.FreeCoTaskMem(wtd.Choice.pFile); } @@ -1170,9 +1170,9 @@ namespace System.Management.Automation.Security } finally { - ClrFacade.DestroyStructure(wtdBuffer); + Marshal.DestroyStructure(wtdBuffer); Marshal.FreeCoTaskMem(wtdBuffer); - ClrFacade.DestroyStructure(WINTRUST_ACTION_GENERIC_VERIFY_V2); + Marshal.DestroyStructure(WINTRUST_ACTION_GENERIC_VERIFY_V2); Marshal.FreeCoTaskMem(WINTRUST_ACTION_GENERIC_VERIFY_V2); } } diff --git a/src/System.Management.Automation/utils/ClrFacade.cs b/src/System.Management.Automation/utils/ClrFacade.cs index 87e3417133..80026085a3 100644 --- a/src/System.Management.Automation/utils/ClrFacade.cs +++ b/src/System.Management.Automation/utils/ClrFacade.cs @@ -78,15 +78,6 @@ namespace System.Management.Automation return Marshal.SizeOf(); } - /// - /// Facade for Marshal.DestroyStructure - /// - internal static void DestroyStructure(IntPtr ptr) - { - // Marshal.DestroyStructure(IntPtr, Type) is obsolete in CoreCLR - Marshal.DestroyStructure(ptr); - } - /// /// Facade for Marshal.PtrToStructure ///