-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 refcount when a composite r2r image is loaded from a bundle #61066
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reading of the issue is that we were using
NewHolder
instead ofPEImageLayoutHolder
/ReleaseHolder
, which meant thatSuppressRelease
wouldn't prevent thedelete
when theNewHolder
went out of scope.We could have switched to
PEImageLayoutHolder
and kept what this was doing before (usingSuppressRelease
). However, with the switch to callingPEImage::OpenImage
withMDInternalImport_NoCache
, thepImage
will not be cached, so it (and therefore the layout created throughGetOrCreateLayout
) will be released once it goes out of scope - hence we need to do theAddRef
instead so that we keep thePEImageLayout
around without thePEImage
.Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, it might be worth having an explicit comment around that. My initial reaction looking at this was that it would make more sense to keep with the
SuppressRelease
(instead of the explicitAddRef
and let the holder release) - before I saw the implications of the switch toMDInternalImport_NoCache
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would work too.
SuppressRelease
would effectively "leak" the PE image and that would keep the layout alive. We would not have a way to free the layout, but in this case it would be ok.On the other hand we only need this PE image to get the layout and we will not be doing that again, since AppDomain caches the native image. I figured I'd rather take the ownership of the layout (by doing AddRef) and let PE image instance be freed.
Using cache is not required here since composite r2r PE is not a part of anyone's identity.
Since we will open the image only once anyways, I just thought we should not involve the cache, regardless if we keep/leak PE image or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a better comment about the whole deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments.