From 1bed14532ccd51590ec9d6771a8b1152133a2a20 Mon Sep 17 00:00:00 2001 From: yankejustin Date: Tue, 17 Mar 2015 14:08:22 -0400 Subject: [PATCH] Reflected changes to ProtoBuf classes Reflected the changes made to the ProtoBuf classes to both sides. --- Client/Core/ProtoBuf/BufferExtension.cs | 35 ++++++++++++++----------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Client/Core/ProtoBuf/BufferExtension.cs b/Client/Core/ProtoBuf/BufferExtension.cs index 5d5fcdce..01de999d 100644 --- a/Client/Core/ProtoBuf/BufferExtension.cs +++ b/Client/Core/ProtoBuf/BufferExtension.cs @@ -27,18 +27,18 @@ void IExtension.EndAppend(Stream stream, bool commit) int len; if (commit && (len = (int)stream.Length) > 0) { - MemoryStream ms = (MemoryStream)stream; - - if (buffer == null) - { // allocate new buffer - buffer = ms.ToArray(); - } - else - { // resize and copy the data - // note: Array.Resize not available on CF - int offset = buffer.Length; - byte[] tmp = new byte[offset + len]; - Helpers.BlockCopy(buffer, 0, tmp, 0, offset); + using (MemoryStream ms = (MemoryStream)stream) + { + if (buffer == null) + { // allocate new buffer + buffer = ms.ToArray(); + } + else + { // resize and copy the data + // note: Array.Resize not available on CF + int offset = buffer.Length; + byte[] tmp = new byte[offset + len]; + Helpers.BlockCopy(buffer, 0, tmp, 0, offset); #if PORTABLE || WINRT // no GetBuffer() - fine, we'll use Read instead int bytesRead; @@ -52,9 +52,10 @@ void IExtension.EndAppend(Stream stream, bool commit) if(len != 0) throw new EndOfStreamException(); ms.Position = oldPos; #else - Helpers.BlockCopy(ms.GetBuffer(), 0, tmp, offset, len); + Helpers.BlockCopy(ms.GetBuffer(), 0, tmp, offset, len); #endif - buffer = tmp; + buffer = tmp; + } } } } @@ -67,7 +68,11 @@ Stream IExtension.BeginQuery() void IExtension.EndQuery(Stream stream) { - using (stream) { } // just clean up + // Clean up + if (stream != null) + { + stream.Dispose(); + } } } }