Fix FileStream leak in ClassPath.IsJmodFile#1424
Open
jonathanpeppers wants to merge 1 commit intodotnet:mainfrom
Open
Fix FileStream leak in ClassPath.IsJmodFile#1424jonathanpeppers wants to merge 1 commit intodotnet:mainfrom
jonathanpeppers wants to merge 1 commit intodotnet:mainfrom
Conversation
Add using to File.OpenRead in IsJmodFile so the stream is disposed on all return paths, matching the pattern used by the companion IsJarFile method. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a file-handle leak in Xamarin.Android.Tools.Bytecode by ensuring ClassPath.IsJmodFile disposes the FileStream it opens while probing JMOD headers, preventing file descriptor exhaustion during high-volume classpath scanning.
Changes:
- Wrap the
File.OpenRead (jmodFile)stream in ausing vardeclaration so it is always disposed (including early-return paths).
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.
Summary
IsJmodFileopened aFileStreamviaFile.OpenReadbut never disposed it. Both the early-return path (when fewer than 4 bytes are read) and the normal-return path left the handle open, leaking a file descriptor on every call. Under high-volume classpath scanning this can exhaust OS file descriptors.Change
In
src/Xamarin.Android.Tools.Bytecode/ClassPath.cs, addusingto the stream declaration inIsJmodFile:This matches the pattern already used by the companion method
IsJarFile(line 133), which correctly wraps its stream in ausingstatement.Verification
dotnet build -t:Prepare && dotnet build— ✅ 0 errorsdotnet test tests/Xamarin.Android.Tools.Bytecode-Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj— ✅ 75 passed, 2 skipped