Skip to content

Commit fca7eda

Browse files
[release/7.0-staging] Fix COM object leak (#89795)
Co-authored-by: Jeremy Koritzinsky <jekoritz@microsoft.com> Co-authored-by: Jeremy Koritzinsky <jkoritzinsky@gmail.com>
1 parent c47d0ab commit fca7eda

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/libraries/Microsoft.Windows.Compatibility/src/Microsoft.Windows.Compatibility.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<!-- Reference the outputs for the dependency nodes calculation. -->
66
<NoTargetsDoNotReferenceOutputAssemblies>false</NoTargetsDoNotReferenceOutputAssemblies>
77
<IsPackable>true</IsPackable>
8-
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
9-
<ServicingVersion>3</ServicingVersion>
8+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
9+
<ServicingVersion>4</ServicingVersion>
1010
<!-- This is a meta package and doesn't contain any libs. -->
1111
<NoWarn>$(NoWarn);NU5128</NoWarn>
1212
<PackageDescription>This Windows Compatibility Pack provides access to APIs that were previously available only for .NET Framework. It can be used from both .NET as well as .NET Standard.</PackageDescription>

src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<Nullable>annotations</Nullable>
1212
<IsPackable>true</IsPackable>
1313
<!-- If you enable GeneratePackageOnBuild for this package and bump ServicingVersion, make sure to also bump ServicingVersion in Microsoft.Windows.Compatibility.csproj once for the next release. -->
14-
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
15-
<ServicingVersion>0</ServicingVersion>
14+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
15+
<ServicingVersion>1</ServicingVersion>
1616
<AddNETFrameworkPlaceholderFileToPackage>true</AddNETFrameworkPlaceholderFileToPackage>
1717
<AddNETFrameworkAssemblyReferenceToPackage>true</AddNETFrameworkAssemblyReferenceToPackage>
1818
<PackageDescription>Provides uniform access and manipulation of user, computer, and group security principals across the multiple principal stores: Active Directory Domain Services (AD DS), Active Directory Lightweight Directory Services (AD LDS), and Machine SAM (MSAM).</PackageDescription>

src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,24 @@ internal static class UnsafeNativeMethods
1919
{
2020
public static int ADsOpenObject(string path, string userName, string password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject)
2121
{
22+
IntPtr ppObjPtr = IntPtr.Zero;
2223
try
2324
{
24-
int hr = Interop.Activeds.ADsOpenObject(path, userName, password, flags, ref iid, out IntPtr ppObjPtr);
25+
int hr = Interop.Activeds.ADsOpenObject(path, userName, password, flags, ref iid, out ppObjPtr);
2526
ppObject = Marshal.GetObjectForIUnknown(ppObjPtr);
2627
return hr;
2728
}
2829
catch (EntryPointNotFoundException)
2930
{
3031
throw new InvalidOperationException(SR.AdsiNotInstalled);
3132
}
33+
finally
34+
{
35+
if (ppObjPtr != IntPtr.Zero)
36+
{
37+
Marshal.Release(ppObjPtr);
38+
}
39+
}
3240
}
3341

3442
//

0 commit comments

Comments
 (0)