diff --git a/src/coreclr/vm/dynamicmethod.cpp b/src/coreclr/vm/dynamicmethod.cpp index 541d88dc168859..6b6c5ffacce4e7 100644 --- a/src/coreclr/vm/dynamicmethod.cpp +++ b/src/coreclr/vm/dynamicmethod.cpp @@ -380,7 +380,7 @@ HostCodeHeap::~HostCodeHeap() delete[] m_pHeapList->pHdrMap; if (m_pBaseAddr) - ClrVirtualFree(m_pBaseAddr, 0, MEM_RELEASE); + ExecutableAllocator::Instance()->Release(m_pBaseAddr); LOG((LF_BCL, LL_INFO10, "Level1 - CodeHeap destroyed {0x%p}\n", this)); } diff --git a/src/coreclr/vm/loaderallocator.cpp b/src/coreclr/vm/loaderallocator.cpp index 0a77e4445f06f7..08ef69c1281acc 100644 --- a/src/coreclr/vm/loaderallocator.cpp +++ b/src/coreclr/vm/loaderallocator.cpp @@ -1414,7 +1414,7 @@ void LoaderAllocator::Terminate() // This was the block reserved by BaseDomain::Init for the loaderheaps. if (m_InitialReservedMemForLoaderHeaps) { - ClrVirtualFree (m_InitialReservedMemForLoaderHeaps, 0, MEM_RELEASE); + ExecutableAllocator::Instance()->Release(m_InitialReservedMemForLoaderHeaps); m_InitialReservedMemForLoaderHeaps=NULL; } @@ -1687,7 +1687,11 @@ void AssemblyLoaderAllocator::Init(AppDomain* pAppDomain) LoaderAllocator::Init((BaseDomain *)pAppDomain); if (IsCollectible()) { - m_pShuffleThunkCache = new ShuffleThunkCache(m_pStubHeap); + // TODO: the ShuffleThunkCache should really be using the m_pStubHeap, however the unloadability support + // doesn't track the stubs or the related delegate classes and so we get crashes when a stub is used after + // the AssemblyLoaderAllocator is gone (the stub memory is unmapped). + // https://github.com/dotnet/runtime/issues/55697 tracks this issue. + m_pShuffleThunkCache = new ShuffleThunkCache(SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap()); } }