Repository navigation
Unmap empty memory-mapped views on Unix - #136793
Open
RutulPatel8 wants to merge 2 commits into
Open
RutulPatel8 wants to merge 2 commits into
RutulPatel8 wants to merge 2 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the empty-view mapping disposal fix.
No open issues 🎉
What changed in this PR
Fixes the Unix empty-view mapping leak described in #133744 by recording the actual native mapping length so disposal can unmap it.
Changes:
- Records the one-byte native size used when mapping an empty view.
- Adds a Linux regression test using
mincoreto verify the mapping exists before disposal and is released afterward.
| File | Description |
|---|---|
src/libraries/System.IO.MemoryMappedFiles/tests/SafeMemoryMappedViewHandleTests.cs |
Adds the Linux disposal regression test and mincore interop declaration. |
src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs |
Records and uses the actual native size for empty mappings. |
Review effort: Balanced
jkotas
reviewed
Nov 2, 2026
| Assert.Equal(0, MinCore(address, 1, &residency)); | ||
| } | ||
|
|
||
| Assert.Equal(-1, MinCore(address, 1, &residency)); |
Member
There was a problem hiding this comment.
What guarantees that some other thread won't map something else at this address?
jkotas
reviewed
Nov 2, 2026
| using MemoryMappedFile mmf = MemoryMappedFile.CreateNew(null, 4096); | ||
| using MemoryMappedViewStream view = mmf.CreateViewStream(4096, 0); | ||
|
|
||
| // ReleaseHandle passes ByteLength to munmap. A zero-length view still maps one byte. |
Member
There was a problem hiding this comment.
Can we avoid this Unix-specific behavior change?
This branch has not been deployed
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #133744
When a zero-length Unix view is created,
mmapmaps one byte because a zero-length mapping is invalid. The view handle was initialized with the requested native size of zero, so disposal calledmunmap(address, 0)and leaked the mapping.Record the actual one-byte native mapping size. Add a Linux regression test that checks the address is mapped while the view is alive and unmapped after disposal using
mincore.Validation: System.IO.MemoryMappedFiles library and test projects build successfully across their configured targets. The Linux test could not run on this Windows host; CI should execute it.