Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/coreclr/debug/daccess/dacimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ class DefaultCOMImpl : public T

ULONG STDMETHODCALLTYPE Release()
{
ULONG res = mRef--;
ULONG res = --mRef;
if (res == 0)
delete this;
return res;
Expand Down
14 changes: 11 additions & 3 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,19 @@ ClrDataAccess::GetMethodTableSlotEnumerator(CLRDATA_ADDRESS mt, ISOSMethodEnum *
else
{
DacMethodTableSlotEnumerator *methodTableSlotEnumerator = new (nothrow) DacMethodTableSlotEnumerator();
*enumerator = methodTableSlotEnumerator;
if (*enumerator == NULL)
if (methodTableSlotEnumerator == NULL)
{
hr = E_OUTOFMEMORY;
}
else
{
hr = methodTableSlotEnumerator->Init(mTable);

if (SUCCEEDED(hr))
hr = methodTableSlotEnumerator->QueryInterface(__uuidof(ISOSMethodEnum), (void**)enumerator);

if (FAILED(hr))
delete methodTableSlotEnumerator;
}
}

Expand Down Expand Up @@ -3969,7 +3974,10 @@ ClrDataAccess::Request(IN ULONG32 reqCode,
}
else
{
*(ULONG32*)outBuffer = 9;
// Revision 10: Fixed DefaultCOMImpl::Release() to use pre-decrement (--mRef).
// Consumers that previously compensated for the broken ref counting (e.g., ClrMD)
// should check this revision to avoid double-freeing.
*(ULONG32*)outBuffer = 10;
status = S_OK;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1528,9 +1528,6 @@ int ISOSDacInterface.GetHandleEnum(DacComNullableByRef<ISOSHandleEnum> ppHandleE
}
#endif
ppHandleEnum.Interface = new SOSHandleEnum(_target, supportedHandleTypes, legacyHandleEnum);
// COMPAT: In the legacy DAC, this API leaks a ref-count of the returned enumerator.
// Manually leak a refcount here to match previous behavior and avoid breaking customer code.
ComInterfaceMarshaller<ISOSHandleEnum>.ConvertToUnmanaged(ppHandleEnum.Interface);
}
catch (System.Exception ex)
{
Expand Down Expand Up @@ -1558,9 +1555,6 @@ int ISOSDacInterface.GetHandleEnumForTypes([In, MarshalUsing(CountElementName =
IGC gc = _target.Contracts.GC;
HandleType[] handleTypes = gc.GetHandleTypes(types);
ppHandleEnum.Interface = new SOSHandleEnum(_target, handleTypes, legacyHandleEnum);
// COMPAT: In the legacy DAC, this API leaks a ref-count of the returned enumerator.
// Manually leak a refcount here to match previous behavior and avoid breaking customer code.
ComInterfaceMarshaller<ISOSHandleEnum>.ConvertToUnmanaged(ppHandleEnum.Interface);
}
catch (System.Exception ex)
{
Expand Down
Loading