Skip to content

Commit

Permalink
Lucene.Net.Store.InputStreamDataInput: Allow double-dispose calls and…
Browse files Browse the repository at this point in the history
… guard against usage after Dispose(). See #265.
  • Loading branch information
NightOwl888 committed May 16, 2023
1 parent a9c8388 commit 5336dfc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Lucene.Net/Store/InputStreamDataInput.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Threading;

namespace Lucene.Net.Store
{
Expand All @@ -26,6 +27,7 @@ namespace Lucene.Net.Store
public class InputStreamDataInput : DataInput, IDisposable
{
private readonly Stream _is;
private int disposed = 0; // LUCENENET specific - allow double-dispose

public InputStreamDataInput(Stream @is)
{
Expand Down Expand Up @@ -65,6 +67,8 @@ public void Dispose()

protected virtual void Dispose(bool disposing)
{
if (0 != Interlocked.CompareExchange(ref this.disposed, 1, 0)) return; // LUCENENET specific - allow double-dispose

if (disposing)
{
_is.Dispose();
Expand Down

0 comments on commit 5336dfc

Please sign in to comment.