MemoryMappedView leak
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
> A few more findings from the same 64KiB-page machine, separate from the thunk and GC bitmap-accounting issues above:
>
> 2. **Empty memory-mapped views leak one OS-page mapping on Unix.** [`CreateView`](https://github.com/dotnet/runtime/blob/f8bd1824ce4033c661594206b4f9e037d05ae9f1/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs#L94-L125) maps one byte for an empty view but records a native length of zero. Disposal then calls `munmap(address, 0)`, which fails. Reproduced against the locally built libraries: all 32 disposed empty views remained mapped. This isn't exclusive to 64KiB pages, but the leaked virtual mapping is 64KiB per view here, rather than 4KiB.
>
_Originally posted by @EgorBo in [#133675](https://github.com/dotnet/runtime/issues/133675#issuecomment-5634376847)_
Contributor guide
Research direction
Start in src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs, especially CreateView and the disposal path. Reproduce with empty views and verify that disposal successfully unmaps the OS-page mapping instead of calling munmap with a zero native length; add or update coverage for the empty-view case if the surrounding tests identify a suitable location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 74/100