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:12 UTC
[lucenenet] 06/07: Lucene.Net.Store.InputStreamDataInput: 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 5336dfc16e38c9ced9dbc3b4ab138cc0828e507e
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sun May 14 23:03:28 2023 +0700
Lucene.Net.Store.InputStreamDataInput: Allow double-dispose calls and guard against usage after Dispose(). See #265.
---
src/Lucene.Net/Store/InputStreamDataInput.cs | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/Lucene.Net/Store/InputStreamDataInput.cs b/src/Lucene.Net/Store/InputStreamDataInput.cs
index b9462397a..8b450561b 100644
--- a/src/Lucene.Net/Store/InputStreamDataInput.cs
+++ b/src/Lucene.Net/Store/InputStreamDataInput.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 InputStreamDataInput : DataInput, IDisposable
{
private readonly Stream _is;
+ private int disposed = 0; // LUCENENET specific - allow double-dispose
public InputStreamDataInput(Stream @is)
{
@@ -65,6 +67,8 @@ namespace Lucene.Net.Store
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();