This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Fix resource stream for collectible assemblies#22925
Merged
Merged
Conversation
The GetManifestResourceStream was returning a stream that didn't keep the underlying assembly alive. For collectible assemblies, that means that an assembly could be collected and the stream still kept, potentially reading garbage. The fix is to create a new stream type that stores a reference to the underlying assembly, thus ensuring the proper lifetime management.
Member
Author
|
cc: @marek-safar |
marek-safar
reviewed
Feb 28, 2019
|
|
||
| private class ManifestResourceStream : UnmanagedMemoryStream | ||
| { | ||
| private RuntimeAssembly _manifestAssembly; |
There was a problem hiding this comment.
What about releasing the reference on explicit Dispose?
Member
There was a problem hiding this comment.
Explicit Dispose does not guarantee that nobody is accessing the memory anymore
There was a problem hiding this comment.
fair enough, it'd have to invalidate the object state (maybe v2)
marek-safar
reviewed
Feb 28, 2019
|
|
||
| #endregion | ||
|
|
||
| private class ManifestResourceStream : UnmanagedMemoryStream |
jkotas
approved these changes
Feb 28, 2019
Member
Author
|
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please |
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
* Fix resource stream for collectible assemblies The GetManifestResourceStream was returning a stream that didn't keep the underlying assembly alive. For collectible assemblies, that means that an assembly could be collected and the stream still kept, potentially reading garbage. The fix is to create a new stream type that stores a reference to the underlying assembly, thus ensuring the proper lifetime management. * Make the new stream class sealed Commit migrated from dotnet/coreclr@452c40d
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The GetManifestResourceStream was returning a stream that didn't keep
the underlying assembly alive. For collectible assemblies, that means
that an assembly could be collected and the stream still kept,
potentially reading garbage.
The fix is to create a new stream type that stores a reference to the
underlying assembly, thus ensuring the proper lifetime management.
I have also added a regression test that checks that the stream keeps the underlying assembly alive and it also checks that once the stream reference is gone, the assembly is collected.