Skip to content

Commit

Permalink
Fix refcount when a composite r2r image is loaded from a bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
VSadov committed Nov 1, 2021
1 parent 966ca29 commit a1877fd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/coreclr/vm/nativeimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,17 @@ NativeImage *NativeImage::Open(
LPWSTR searchPathsConfig;
IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_NativeImageSearchPaths, &searchPathsConfig));

NewHolder<PEImageLayout> peLoadedImage;
PEImageLayoutHolder peLoadedImage;

BundleFileLocation bundleFileLocation = Bundle::ProbeAppBundle(fullPath, /*pathIsBundleRelative */ true);
if (bundleFileLocation.IsValid())
{
PEImageHolder pImage = PEImage::OpenImage(fullPath, MDInternalImport_Default, bundleFileLocation);
peLoadedImage = pImage->GetOrCreateLayout(PEImageLayout::LAYOUT_MAPPED);
peLoadedImage.SuppressRelease();
// No need to use cache for this PE image. It is transient.
// We only need it to obtain the native image, which AppDomain will keep.
PEImageHolder pImage = PEImage::OpenImage(fullPath, MDInternalImport_NoCache, bundleFileLocation);
PEImageLayout* mapped = pImage->GetOrCreateLayout(PEImageLayout::LAYOUT_MAPPED);
mapped->AddRef();
peLoadedImage = mapped;
}

if (peLoadedImage.IsNull())
Expand Down

0 comments on commit a1877fd

Please sign in to comment.