dotnet / dotnet/runtime

MemoryMappedView leak

Open Beginner friendly
#133,744 1 comment 0 reactions 0 assignees View on GitHub
area-System.IO
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.