Skip to content

Commit

Permalink
[PixImage] Fix leak in Windows Media loader
Browse files Browse the repository at this point in the history
Trying to load a file directly leads to a handle leak in case of failure.
Reproducible in PGM loader test.
  • Loading branch information
hyazinthh committed Oct 18, 2023
1 parent b159a19 commit 05021b8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Aardvark.PixImage.WindowsMedia/PixImageWindowsMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@ private class PixLoader : IPixLoader
/// </summary>
public PixImage LoadFromFile(string filename)
{
using var stream = new MemoryStream(File.ReadAllBytes(filename));

var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(filename, UriKind.RelativeOrAbsolute);
bitmapImage.StreamSource = stream;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.CreateOptions = BitmapCreateOptions.None
| BitmapCreateOptions.PreservePixelFormat;
bitmapImage.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
bitmapImage.EndInit();
return CreateFromBitmapSource(bitmapImage);
}
Expand Down

0 comments on commit 05021b8

Please sign in to comment.