aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
diff options
context:
space:
mode:
authorClaus Vium <cvium@users.noreply.github.com>2023-08-20 20:06:57 +0200
committerGitHub <noreply@github.com>2023-08-20 20:06:57 +0200
commit956e3dab43413798909a85a958231c3a16ac7b7f (patch)
tree43d96ad727638ae86c42ef9eac2c4de5dc7c1635 /MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
parent260680d727cd96b149ddf122be05feb4772a0dc7 (diff)
fix: accessing Standard* of a Process requires manually disposing them afterwards (#10125)
Diffstat (limited to 'MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs')
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs13
1 files changed, 8 insertions, 5 deletions
diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
index 38118ed0e..db119ce5c 100644
--- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
@@ -553,7 +553,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
private string GetProcessOutput(string path, string arguments, bool readStdErr, string? testKey)
{
- using (var process = new Process()
+ var redirectStandardIn = !string.IsNullOrEmpty(testKey);
+ using (var process = new Process
{
StartInfo = new ProcessStartInfo(path, arguments)
{
@@ -561,7 +562,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false,
- RedirectStandardInput = !string.IsNullOrEmpty(testKey),
+ RedirectStandardInput = redirectStandardIn,
RedirectStandardOutput = true,
RedirectStandardError = true
}
@@ -571,12 +572,14 @@ namespace MediaBrowser.MediaEncoding.Encoder
process.Start();
- if (!string.IsNullOrEmpty(testKey))
+ if (redirectStandardIn)
{
- process.StandardInput.Write(testKey);
+ using var writer = process.StandardInput;
+ writer.Write(testKey);
}
- return readStdErr ? process.StandardError.ReadToEnd() : process.StandardOutput.ReadToEnd();
+ using var reader = readStdErr ? process.StandardError : process.StandardOutput;
+ return reader.ReadToEnd();
}
}
}