You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2023/05/16 21:03:13 UTC
[lucenenet] 07/07: Lucene.Net.Store.OutputStreamDataOutput: Allow double-dispose calls and guard against usage after Dispose(). See #265.
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit e9c47b2dea45097a2761ebf2b3695adc456e8f26
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sun May 14 23:04:14 2023 +0700
Lucene.Net.Store.OutputStreamDataOutput: Allow double-dispose calls and guard against usage after Dispose(). See #265.
---
src/Lucene.Net/Store/OutputStreamDataOutput.cs | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/Lucene.Net/Store/OutputStreamDataOutput.cs b/src/Lucene.Net/Store/OutputStreamDataOutput.cs
index f635a2b36..7a96de6a8 100644
--- a/src/Lucene.Net/Store/OutputStreamDataOutput.cs
+++ b/src/Lucene.Net/Store/OutputStreamDataOutput.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Threading;
namespace Lucene.Net.Store
{
@@ -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)
{
@@ -60,6 +62,8 @@ namespace Lucene.Net.Store
// 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();