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>
{
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);
losslessDecoder.Decode(pixelBufferDecoded, (int)webpInfo.Width, (int)webpInfo.Height);
decodedImage?.Dispose();
throw;
}
else
finally
{
var lossyDecoder = new WebpLossyDecoder(webpInfo.Vp8BitReader, this.memoryAllocator, this.configuration);
lossyDecoder.Decode(pixelBufferDecoded, (int)webpInfo.Width, (int)webpInfo.Height, webpInfo, this.AlphaData);
webpInfo.Dispose();
}
return decodedImage;

6
tests/ImageSharp.Tests/MemoryAllocatorValidator.cs

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

Loading…
Cancel
Save