From db91a98e1b9f74b39668a0572134e8b5c4f0c405 Mon Sep 17 00:00:00 2001 From: "Nikitin A. Kirill" Date: Fri, 6 Aug 2021 15:31:03 +0400 Subject: [PATCH] Fix Issue#55518 (#56668) --- src/coreclr/vm/assembly.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 9ef8f08..2c64145 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -579,6 +579,13 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, ICLRPrivBinder* pBinderCon { GCX_PREEMP(); + AssemblyLoaderAllocator* pBinderAssemblyLoaderAllocator = nullptr; + + if (pBinderContext != nullptr) + { + pBinderContext->GetLoaderAllocator((LPVOID*)&pBinderAssemblyLoaderAllocator); + } + // Create a new LoaderAllocator if appropriate if ((args->access & ASSEMBLY_ACCESS_COLLECT) != 0) { @@ -595,17 +602,15 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, ICLRPrivBinder* pBinderCon // atomically transfered by call to LoaderAllocator::ActivateManagedTracking(). pAssemblyLoaderAllocator->SetupManagedTracking(&args->loaderAllocator); createdNewAssemblyLoaderAllocator = TRUE; - } - else - { - AssemblyLoaderAllocator* pAssemblyLoaderAllocator = nullptr; - if (pBinderContext != nullptr) + if(pBinderAssemblyLoaderAllocator != nullptr) { - pBinderContext->GetLoaderAllocator((LPVOID*)&pAssemblyLoaderAllocator); + pAssemblyLoaderAllocator->EnsureReference(pBinderAssemblyLoaderAllocator); } - - pLoaderAllocator = pAssemblyLoaderAllocator == nullptr ? pDomain->GetLoaderAllocator() : pAssemblyLoaderAllocator; + } + else + { + pLoaderAllocator = pBinderAssemblyLoaderAllocator == nullptr ? pDomain->GetLoaderAllocator() : pBinderAssemblyLoaderAllocator; } if (!createdNewAssemblyLoaderAllocator) -- 2.7.4