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

Fix DynamicMethodDesc::Destroy vs code heap enumeration race #713

Merged
Merged
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
25 changes: 15 additions & 10 deletions src/coreclr/src/vm/dynamicmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,22 +849,27 @@ void DynamicMethodDesc::Destroy()

_ASSERTE(IsDynamicMethod());
LoaderAllocator *pLoaderAllocator = GetLoaderAllocator();

LOG((LF_BCL, LL_INFO1000, "Level3 - Destroying DynamicMethod {0x%p}\n", this));
if (!m_pSig.IsNull())

// The m_pSig and m_pszMethodName need to be destroyed after the GetLCGMethodResolver()->Destroy() call
// otherwise the EEJitManager::CodeHeapIterator could return DynamicMethodDesc with these members NULLed, but
// the nibble map for the corresponding code memory indicating that this DynamicMethodDesc is still alive.
PCODE pSig = m_pSig.GetValue();
PTR_CUTF8 pszMethodName = m_pszMethodName.GetValue();

GetLCGMethodResolver()->Destroy();
// The current DynamicMethodDesc storage is destroyed at this point

if (pszMethodName != NULL)
{
delete[] (BYTE*)m_pSig.GetValue();
m_pSig.SetValueMaybeNull(NULL);
delete[] pszMethodName;
}
m_cSig = 0;
if (!m_pszMethodName.IsNull())

if (pSig != NULL)
{
delete[] m_pszMethodName.GetValue();
m_pszMethodName.SetValueMaybeNull(NULL);
delete[] (BYTE*)pSig;
}

GetLCGMethodResolver()->Destroy();

if (pLoaderAllocator->IsCollectible())
{
if (pLoaderAllocator->Release())
Expand Down