From 6ed13c3b41e7e6dfabc9215c8a69e0d9c84f0d85 Mon Sep 17 00:00:00 2001 From: Dan Kroymann Date: Thu, 17 Feb 2022 09:16:06 -0800 Subject: [PATCH] Fix a bug in LoadAsync(filePath) where the FileStream was being disposed too early --- src/ImageSharp/Image.FromFile.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index fce0835fb..345a5e6c8 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -298,7 +298,7 @@ namespace SixLabors.ImageSharp /// Image format is not supported. /// Image contains invalid content. /// A representing the asynchronous operation. - public static Task LoadAsync( + public static async Task LoadAsync( Configuration configuration, string path, IImageDecoder decoder, @@ -308,7 +308,8 @@ namespace SixLabors.ImageSharp Guard.NotNull(path, nameof(path)); using Stream stream = configuration.FileSystem.OpenRead(path); - return LoadAsync(configuration, stream, decoder, cancellationToken); + return await LoadAsync(configuration, stream, decoder, cancellationToken) + .ConfigureAwait(false); } /// @@ -326,7 +327,7 @@ namespace SixLabors.ImageSharp /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. - public static Task> LoadAsync( + public static async Task> LoadAsync( Configuration configuration, string path, IImageDecoder decoder, @@ -337,7 +338,8 @@ namespace SixLabors.ImageSharp Guard.NotNull(path, nameof(path)); using Stream stream = configuration.FileSystem.OpenRead(path); - return LoadAsync(configuration, stream, decoder, cancellationToken); + return await LoadAsync(configuration, stream, decoder, cancellationToken) + .ConfigureAwait(false); } ///