Skip to content

Commit

Permalink
Lucene.Net.Store.OutputStreamDataOutput: Allow double-dispose calls a…
Browse files Browse the repository at this point in the history
…nd guard against usage after Dispose(). See #265.
  • Loading branch information
NightOwl888 committed May 16, 2023
1 parent 5336dfc commit e9c47b2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Lucene.Net/Store/OutputStreamDataOutput.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 OutputStreamDataOutput : DataOutput, IDisposable
{
private readonly Stream _os;
private int disposed = 0; // LUCENENET specific - allow double-dispose

public OutputStreamDataOutput(Stream os)
{
Expand Down Expand Up @@ -60,6 +62,8 @@ public void Dispose()
// LUCENENET specific - implemented proper dispose pattern
protected virtual void Dispose(bool disposing)
{
if (0 != Interlocked.CompareExchange(ref this.disposed, 1, 0)) return; // LUCENENET specific - allow double-dispose

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

0 comments on commit e9c47b2

Please sign in to comment.