diff --git a/XmppSharp/XmppParser.cs b/XmppSharp/XmppParser.cs index 0065d22..c4ae2df 100644 --- a/XmppSharp/XmppParser.cs +++ b/XmppSharp/XmppParser.cs @@ -15,9 +15,9 @@ public sealed class XmppParser : IDisposable private readonly bool _leaveOpen; - private readonly Func _streamFactory; + private Func _streamFactory; private Stream _baseStream; - private bool _isFromFactory; + private readonly bool _isFromFactory; private readonly Encoding _encoding; private readonly int _bufferSize; @@ -58,8 +58,8 @@ public XmppParser(Func streamFactory, Encoding? encoding = default, int { Require.NotNull(streamFactory); - this._streamFactory = streamFactory; this._isFromFactory = true; + this._streamFactory = streamFactory; Reset(); } @@ -89,7 +89,9 @@ public void Dispose() this._disposed = true; - if (!this._isFromFactory) + if (this._isFromFactory) + this._streamFactory = null; + else { if (!this._leaveOpen) this._baseStream?.Dispose();