From 7e85b1e27eaa3926e9a2b38c413fc31721e365ef Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Wed, 20 Oct 2021 17:19:52 +0200 Subject: [PATCH] Use dispose pattern --- .../Formats/Webp/BitReader/BitReaderBase.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Webp/BitReader/BitReaderBase.cs b/src/ImageSharp/Formats/Webp/BitReader/BitReaderBase.cs index 47d1581237..f11f2a1100 100644 --- a/src/ImageSharp/Formats/Webp/BitReader/BitReaderBase.cs +++ b/src/ImageSharp/Formats/Webp/BitReader/BitReaderBase.cs @@ -13,6 +13,8 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitReader /// internal abstract class BitReaderBase : IDisposable { + private bool isDisposed; + /// /// Gets or sets the raw encoded image data. /// @@ -31,7 +33,26 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitReader input.Read(dataSpan.Slice(0, bytesToRead), 0, bytesToRead); } + protected virtual void Dispose(bool disposing) + { + if (this.isDisposed) + { + return; + } + + if (disposing) + { + this.Data?.Dispose(); + } + + this.isDisposed = true; + } + /// - public void Dispose() => this.Data?.Dispose(); + public void Dispose() + { + this.Dispose(disposing: true); + GC.SuppressFinalize(this); + } } }