Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jkoritzinsky opened this issue Jun 23, 2021 · 0 comments · Fixed by #54701
Closed

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

jkoritzinsky opened this issue Jun 23, 2021 · 0 comments · Fixed by #54701
Labels
area-VM-coreclr untriaged New issue has not been triaged by the area owner

Comments

@jkoritzinsky
Copy link
Member

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);
}

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jun 23, 2021
jkoritzinsky added a commit to jkoritzinsky/runtime that referenced this issue Jun 24, 2021
…n-array new allocator for MethodDataObject and MethodDataInterfaceImpl.

Fixes dotnet#54637
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 24, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 28, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jul 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-coreclr untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant