Skip to content

Commit f01b696

Browse files
committed
Dont use using statement for encodedAlphaData.
It will now be disposed in a try / finally block.
1 parent d7cd46f commit f01b696

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,11 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
349349
int alphaDataSize = 0;
350350
bool alphaCompressionSucceeded = false;
351351
Span<byte> alphaData = Span<byte>.Empty;
352+
IMemoryOwner<byte> encodedAlphaData = null;
352353
if (hasAlpha)
353354
{
354355
// TODO: This can potentially run in an separate task.
355-
using IMemoryOwner<byte> encodedAlphaData = AlphaEncoder.EncodeAlpha(
356+
encodedAlphaData = AlphaEncoder.EncodeAlpha(
356357
image,
357358
this.configuration,
358359
this.memoryAllocator,
@@ -405,16 +406,23 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
405406
ExifProfile exifProfile = this.skipMetadata ? null : metadata.ExifProfile;
406407
XmpProfile xmpProfile = this.skipMetadata ? null : metadata.XmpProfile;
407408

408-
this.bitWriter.WriteEncodedImageToStream(
409-
stream,
410-
exifProfile,
411-
xmpProfile,
412-
metadata.IccProfile,
413-
(uint)width,
414-
(uint)height,
415-
hasAlpha,
416-
alphaData[..alphaDataSize],
417-
this.alphaCompression && alphaCompressionSucceeded);
409+
try
410+
{
411+
this.bitWriter.WriteEncodedImageToStream(
412+
stream,
413+
exifProfile,
414+
xmpProfile,
415+
metadata.IccProfile,
416+
(uint)width,
417+
(uint)height,
418+
hasAlpha,
419+
alphaData[..alphaDataSize],
420+
this.alphaCompression && alphaCompressionSucceeded);
421+
}
422+
finally
423+
{
424+
encodedAlphaData?.Dispose();
425+
}
418426
}
419427

420428
/// <inheritdoc/>

0 commit comments

Comments
 (0)