Commit d1f26f12 authored by justcoding121's avatar justcoding121

prevent dispose() called twice

parent 879c30ed
...@@ -15,7 +15,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -15,7 +15,7 @@ namespace Titanium.Web.Proxy.Helpers
private readonly CustomBufferedStream stream; private readonly CustomBufferedStream stream;
private readonly Encoding encoding; private readonly Encoding encoding;
private volatile bool disposed; private bool disposed;
internal byte[] Buffer { get; } internal byte[] Buffer { get; }
......
...@@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <seealso cref="System.IO.Stream" /> /// <seealso cref="System.IO.Stream" />
internal class CustomBufferedStream : Stream internal class CustomBufferedStream : Stream
{ {
private static readonly AsyncCallback readCallback = ReadCallback; private readonly AsyncCallback readCallback = ReadCallback;
private readonly Stream baseStream; private readonly Stream baseStream;
...@@ -26,6 +26,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -26,6 +26,7 @@ namespace Titanium.Web.Proxy.Helpers
private int bufferPos; private int bufferPos;
private bool disposed;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="CustomBufferedStream"/> class. /// Initializes a new instance of the <see cref="CustomBufferedStream"/> class.
/// </summary> /// </summary>
...@@ -356,9 +357,14 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -356,9 +357,14 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
baseStream.Dispose(); if(!disposed)
BufferPool.ReturnBuffer(streamBuffer); {
streamBuffer = null; disposed = true;
baseStream.Dispose();
BufferPool.ReturnBuffer(streamBuffer);
streamBuffer = null;
}
} }
/// <summary> /// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment