From 40c280a23cd4ca4a97ec075037060cfbbd1d312d Mon Sep 17 00:00:00 2001 From: morkt Date: Thu, 3 Sep 2015 07:05:55 +0400 Subject: [PATCH] (ZLibStream): dispose of supplied stream in case of initialization errors. --- ArcFormats/Properties/AssemblyInfo.cs | 4 ++-- ArcFormats/ZLibStream.cs | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ArcFormats/Properties/AssemblyInfo.cs b/ArcFormats/Properties/AssemblyInfo.cs index 4460365d..1ab6e281 100644 --- a/ArcFormats/Properties/AssemblyInfo.cs +++ b/ArcFormats/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion ("1.1.10.423")] -[assembly: AssemblyFileVersion ("1.1.10.423")] +[assembly: AssemblyVersion ("1.1.10.427")] +[assembly: AssemblyFileVersion ("1.1.10.427")] diff --git a/ArcFormats/ZLibStream.cs b/ArcFormats/ZLibStream.cs index 5673c2b2..0beb7a4b 100644 --- a/ArcFormats/ZLibStream.cs +++ b/ArcFormats/ZLibStream.cs @@ -79,11 +79,20 @@ namespace GameRes.Compression public ZLibStream (Stream stream, CompressionMode mode, CompressionLevel level, bool leave_open = false) { - if (CompressionMode.Decompress == mode) - InitDecompress (stream); - else - InitCompress (stream, level); - m_should_dispose_base = !leave_open; + try + { + if (CompressionMode.Decompress == mode) + InitDecompress (stream); + else + InitCompress (stream, level); + m_should_dispose_base = !leave_open; + } + catch + { + if (!leave_open) + stream.Dispose(); + throw; + } } private void InitDecompress (Stream stream)