Skip to content

Allocation/Deallocation mismatch for MethodTable::MethodData in CoreCLR #54637

@jkoritzinsky

Description

@jkoritzinsky

As part of #54580, I've discovered an alloc/decalloc mismatch in CoreCLR.

We sometimes allocate space for MethodTable::MethodData objects with new[] instead of new, but always delete with delete.

Allocation:

MethodData *pData = NULL;
if (pMTDecl == pMTImpl) {
if (pMTDecl->IsInterface()) {
pData = new MethodDataInterface(pMTDecl);
}
else {
UINT32 cb = MethodDataObject::GetObjectSize(pMTDecl);
NewArrayHolder<BYTE> pb(new BYTE[cb]);
MethodDataHolder h(FindParentMethodDataHelper(pMTDecl));
pData = new (pb.GetValue()) MethodDataObject(pMTDecl, h.GetValue());
pb.SuppressRelease();
}
}
else {
pData = GetMethodDataHelper(
NULL,
0,
pMTDecl,
pMTImpl);
}

Dealloc:

ULONG MethodTable::MethodData::Release()
{
LIMITED_METHOD_CONTRACT;
//@TODO: Must adjust this to use an alternate allocator so that we don't
//@TODO: potentially cause deadlocks on the debug thread.
SUPPRESS_ALLOCATION_ASSERTS_IN_THIS_SCOPE;
ULONG cRef = (ULONG) InterlockedDecrement((LONG*)&m_cRef);
if (cRef == 0) {
delete this;
}
return (cRef);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-VM-coreclruntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions