From 379b5f142c5a257498497a8af71756639bdb788c Mon Sep 17 00:00:00 2001 From: _aLfa_ Date: Thu, 18 Sep 2014 19:14:07 +0200 Subject: [PATCH] Fix exceptional resource leak CID18132 --- src/Forms/Main.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index 80afa8d8b..3633d6109 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -10449,16 +10449,19 @@ namespace Nikse.SubtitleEdit.Forms private static bool IsSpDvdSupFile(string subFileName) { - byte[] buffer = new byte[SpHeader.SpHeaderLength]; - var fs = new FileStream(subFileName, FileMode.Open, FileAccess.Read, FileShare.Read) { Position = 0 }; - int bytesRead = fs.Read(buffer, 0, buffer.Length); - if (bytesRead == buffer.Length) + using (var fs = new FileStream(subFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { + byte[] buffer = new byte[SpHeader.SpHeaderLength]; + if (fs.Read(buffer, 0, buffer.Length) != buffer.Length) + { + return false; + } + var header = new SpHeader(buffer); if (header.Identifier == "SP" && header.NextBlockPosition > 4) { buffer = new byte[header.NextBlockPosition]; - bytesRead = fs.Read(buffer, 0, buffer.Length); + int bytesRead = fs.Read(buffer, 0, buffer.Length); if (bytesRead == buffer.Length) { buffer = new byte[SpHeader.SpHeaderLength]; @@ -10472,7 +10475,6 @@ namespace Nikse.SubtitleEdit.Forms } } } - fs.Close(); return false; }