Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove local CoTaskMemAlloc and CoTaskMemFree.
  • Loading branch information
AaronRobinsonMSFT committed Nov 4, 2021
commit e1fd042e0ff8a3f550a5cfad567e82b31f035b7b
12 changes: 6 additions & 6 deletions src/libraries/System.Data.OleDb/src/DbPropSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public DBPropSet() : base(IntPtr.Zero, true)
internal DBPropSet(int propertysetCount) : this()
{
this.propertySetCount = propertysetCount;
IntPtr countOfBytes = (IntPtr)(propertysetCount * ODB.SizeOf_tagDBPROPSET);
nuint countOfBytes = (nuint)(propertysetCount * ODB.SizeOf_tagDBPROPSET);
RuntimeHelpers.PrepareConstrainedRegions();
try
{ }
finally
{
base.handle = SafeNativeMethods.CoTaskMemAlloc(countOfBytes);
base.handle = Interop.Ole32.CoTaskMemAlloc(countOfBytes);
if (ADP.PtrZero != base.handle)
{
SafeNativeMethods.ZeroMemory(base.handle, (int)countOfBytes);
Expand Down Expand Up @@ -147,10 +147,10 @@ protected override bool ReleaseHandle()
{
SafeNativeMethods.VariantClear(vptr);
}
SafeNativeMethods.CoTaskMemFree(rgProperties);
Interop.Ole32.CoTaskMemFree(rgProperties);
}
}
SafeNativeMethods.CoTaskMemFree(ptr);
Interop.Ole32.CoTaskMemFree(ptr);
}
return true;
}
Expand Down Expand Up @@ -227,7 +227,7 @@ internal void SetPropertySet(int index, Guid propertySet, ItagDBPROP[] propertie
Debug.Assert(Guid.Empty != propertySet, "invalid propertySet");
Debug.Assert((null != properties) && (0 < properties.Length), "invalid properties");

IntPtr countOfBytes = (IntPtr)(properties.Length * ODB.SizeOf_tagDBPROP);
nuint countOfBytes = (nuint)(properties.Length * ODB.SizeOf_tagDBPROP);
tagDBPROPSET propset = new tagDBPROPSET(properties.Length, propertySet);

bool mustRelease = false;
Expand All @@ -244,7 +244,7 @@ internal void SetPropertySet(int index, Guid propertySet, ItagDBPROP[] propertie
finally
{
// must allocate and clear the memory without interruption
propset.rgProperties = SafeNativeMethods.CoTaskMemAlloc(countOfBytes);
propset.rgProperties = Interop.Ole32.CoTaskMemAlloc(countOfBytes);
if (ADP.PtrZero != propset.rgProperties)
{
// clearing is important so that we don't treat existing
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ protected override bool ReleaseHandle()
IntPtr valuePtr = ADP.IntPtrOffset(infoPtr, (k * ODB.SizeOf_tagDBPROPINFO) + ODB.OffsetOf_tagDBPROPINFO_Value);
SafeNativeMethods.VariantClear(valuePtr);
}
SafeNativeMethods.CoTaskMemFree(infoPtr); // was allocated by provider
Interop.Ole32.CoTaskMemFree(infoPtr); // was allocated by provider
}
}
SafeNativeMethods.CoTaskMemFree(ptr);
Interop.Ole32.CoTaskMemFree(ptr);
}

ptr = this.descBuffer;
this.descBuffer = IntPtr.Zero;
if (IntPtr.Zero != ptr)
{
SafeNativeMethods.CoTaskMemFree(ptr);
Interop.Ole32.CoTaskMemFree(ptr);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Data.OleDb/src/RowBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ private static void FreeCoTaskMem(IntPtr buffer, int valueOffset)
// originalValue is pinned managed memory or pointer to emptyStringOffset
if ((ADP.PtrZero != currentValue) && (currentValue != originalValue))
{
SafeNativeMethods.CoTaskMemFree(currentValue);
Interop.Ole32.CoTaskMemFree(currentValue);
}

// for debugability - delay clearing memory until after CoTaskMemFree
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Data.OleDb/src/SafeHandles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ protected override bool ReleaseHandle()
base.handle = IntPtr.Zero;
if (IntPtr.Zero != ptr)
{
SafeNativeMethods.CoTaskMemFree(ptr);
Interop.Ole32.CoTaskMemFree(ptr);
}

ptr = this.handle2;
this.handle2 = IntPtr.Zero;
if (IntPtr.Zero != ptr)
{
SafeNativeMethods.CoTaskMemFree(ptr);
Interop.Ole32.CoTaskMemFree(ptr);
}
return true;
}
Expand Down
6 changes: 0 additions & 6 deletions src/libraries/System.Data.OleDb/src/SafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ namespace System.Data.Common
[SuppressUnmanagedCodeSecurity]
internal static partial class SafeNativeMethods
{
[GeneratedDllImport(Interop.Libraries.Ole32, SetLastError = false)]
internal static partial IntPtr CoTaskMemAlloc(IntPtr cb);

[GeneratedDllImport(Interop.Libraries.Ole32, SetLastError = false)]
internal static partial void CoTaskMemFree(IntPtr handle);

[GeneratedDllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode, PreserveSig = true)]
internal static partial int GetUserDefaultLCID();

Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ System.Data.OleDb.OleDbTransaction</PackageDescription>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Ole32\Interop.CoTaskMemAlloc.cs"
Link="Common\Interop\Windows\Ole32\Interop.CoTaskMemAlloc.cs" />
<Compile Include="$(CommonPath)System\Data\Common\MultipartIdentifier.cs"
Link="Common\System\Data\Common\MultipartIdentifier.cs" />
<Compile Include="AdapterSwitches.cs" />
Expand Down