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); + } } }