Browse Source

Add missing dispose of webpInfo

pull/1985/head
Brian Popow 4 years ago
parent
commit
89d1582da8
  1. 27
      src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs
  2. 6
      tests/ImageSharp.Tests/MemoryAllocatorValidator.cs

27
src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs

@ -248,16 +248,29 @@ namespace SixLabors.ImageSharp.Formats.Webp
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
var decodedImage = new Image<TPixel>((int)frameData.Width, (int)frameData.Height); var decodedImage = new Image<TPixel>((int)frameData.Width, (int)frameData.Height);
Buffer2D<TPixel> pixelBufferDecoded = decodedImage.Frames.RootFrame.PixelBuffer;
if (webpInfo.IsLossless) try
{
Buffer2D<TPixel> pixelBufferDecoded = decodedImage.Frames.RootFrame.PixelBuffer;
if (webpInfo.IsLossless)
{
var losslessDecoder = new WebpLosslessDecoder(webpInfo.Vp8LBitReader, this.memoryAllocator, this.configuration);
losslessDecoder.Decode(pixelBufferDecoded, (int)webpInfo.Width, (int)webpInfo.Height);
}
else
{
var lossyDecoder = new WebpLossyDecoder(webpInfo.Vp8BitReader, this.memoryAllocator, this.configuration);
lossyDecoder.Decode(pixelBufferDecoded, (int)webpInfo.Width, (int)webpInfo.Height, webpInfo, this.AlphaData);
}
}
catch
{ {
var losslessDecoder = new WebpLosslessDecoder(webpInfo.Vp8LBitReader, this.memoryAllocator, this.configuration); decodedImage?.Dispose();
losslessDecoder.Decode(pixelBufferDecoded, (int)webpInfo.Width, (int)webpInfo.Height); throw;
} }
else finally
{ {
var lossyDecoder = new WebpLossyDecoder(webpInfo.Vp8BitReader, this.memoryAllocator, this.configuration); webpInfo.Dispose();
lossyDecoder.Decode(pixelBufferDecoded, (int)webpInfo.Width, (int)webpInfo.Height, webpInfo, this.AlphaData);
} }
return decodedImage; return decodedImage;

6
tests/ImageSharp.Tests/MemoryAllocatorValidator.cs

@ -59,9 +59,9 @@ namespace SixLabors.ImageSharp.Tests
public void Validate(int expectedAllocationCount) public void Validate(int expectedAllocationCount)
{ {
var count = this.TotalRemainingAllocated; int count = this.TotalRemainingAllocated;
var pass = expectedAllocationCount == count; bool pass = expectedAllocationCount == count;
Assert.True(pass, $"Expected a {expectedAllocationCount} undisposed buffers but found {count}"); Assert.True(pass, $"Expected {expectedAllocationCount} undisposed buffers but found {count}");
} }
public void Dispose() public void Dispose()

Loading…
Cancel
Save