Skip to content

✨ Quality: File streams not properly disposed on preview failure#120

Open
halinhtvn3a wants to merge 1 commit into
omeryanar:masterfrom
halinhtvn3a:contribai/improve/quality/file-streams-not-properly-disposed-on-pr
Open

✨ Quality: File streams not properly disposed on preview failure#120
halinhtvn3a wants to merge 1 commit into
omeryanar:masterfrom
halinhtvn3a:contribai/improve/quality/file-streams-not-properly-disposed-on-pr

Conversation

@halinhtvn3a
Copy link
Copy Markdown

Problem

The PreviewFile method opens a file stream with File.Open() but doesn't handle exceptions.
If an exception occurs after opening the stream but before assignment to the Document property,
the stream will leak. This is a resource leak that could cause file locking issues or
exhaust file handles over time, especially when previewing problematic files.

Severity: medium
File: FileExplorer.Extension.RichTextPreview/RichTextViewer.xaml.cs

Solution

Wrap the file opening in a try-catch block to ensure proper disposal:

Changes

  • FileExplorer.Extension.RichTextPreview/RichTextViewer.xaml.cs (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

The `PreviewFile` method opens a file stream with `File.Open()` but doesn't handle exceptions.
If an exception occurs after opening the stream but before assignment to the `Document` property,
the stream will leak. This is a resource leak that could cause file locking issues or
exhaust file handles over time, especially when previewing problematic files.


Affected files: RichTextViewer.xaml.cs

Signed-off-by: halinhtvn3a <77691576+halinhtvn3a@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant