From a30c0efb788558a4524e2e96e8d3d1396de35237 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:00:49 -0800 Subject: [PATCH] Don't dispose hawkfile stream after ReadAllBytes(), fix ReadAllBytes callsites to do disposal properly --- src/BizHawk.Client.Common/RomLoader.cs | 2 +- src/BizHawk.Client.Common/movie/import/IMovieImport.cs | 2 +- src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs | 2 +- src/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs | 2 +- src/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs | 2 +- .../tools/MultiDiskBundler/MultiDiskFileSelector.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index b4c6036c6f..2a8f48877f 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -835,7 +835,7 @@ namespace BizHawk.Client.Common var ext = file.Extension; var gi = Disc.IsValidExtension(ext) ? MakeGameFromDisc(InstantiateDiscFor(path), ext: ext, name: Path.GetFileNameWithoutExtension(file.Name)) - : new RomGame(new(file.CanonicalFullPath)).GameInfo; // need to re-open??? + : new RomGame(file).GameInfo; Game.Name = $"{gi.Name} [{Game.Name/* core name */}]"; } } diff --git a/src/BizHawk.Client.Common/movie/import/IMovieImport.cs b/src/BizHawk.Client.Common/movie/import/IMovieImport.cs index 8604068736..9f04c1fd64 100644 --- a/src/BizHawk.Client.Common/movie/import/IMovieImport.cs +++ b/src/BizHawk.Client.Common/movie/import/IMovieImport.cs @@ -95,7 +95,7 @@ namespace BizHawk.Client.Common using var rom = new HawkFile(result); if (rom.IsArchive) rom.BindFirst(); - var romData = (ReadOnlySpan) rom.ReadAllBytes(); + var romData = new ReadOnlySpan(rom.ReadAllBytes()); int headerBytes = romData.Length % 1024; // assume that all roms have sizes divisible by 1024, and any rest is header romData = romData[headerBytes..]; if (matchesMovieHash(romData)) diff --git a/src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs b/src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs index 1b69d4d6be..994642cf52 100644 --- a/src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs @@ -478,7 +478,7 @@ namespace BizHawk.Client.EmuHawk // to always be copied to the global firmware directory if (hf.IsArchive) { - var ac = new ArchiveChooser(new HawkFile(filePath)); + using var ac = new ArchiveChooser(hf); if (!ac.ShowDialog(this).IsOk()) return; var insideFile = hf.BindArchiveMember(ac.SelectedMemberIndex); diff --git a/src/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs b/src/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs index 30d2bfd69f..22a5d9790b 100644 --- a/src/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs @@ -97,7 +97,7 @@ namespace BizHawk.Client.EmuHawk { if (PalettePath.Text.Length > 0) { - var palette = new HawkFile(PalettePath.Text); + using var palette = new HawkFile(PalettePath.Text); if (palette.Exists) { diff --git a/src/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs b/src/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs index 816ae4ad19..251b182932 100644 --- a/src/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs @@ -87,7 +87,7 @@ namespace BizHawk.Client.EmuHawk filter: FilesystemFilterSet.Palettes, initDir: _config.PathEntries.PalettesAbsolutePathFor(VSystemID.Raw.NES)); if (result is null) return; - HawkFile palette = new(result); + using HawkFile palette = new(result); if (palette.Exists) { diff --git a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskFileSelector.cs b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskFileSelector.cs index 1f1bee18e0..e26c5908f6 100644 --- a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskFileSelector.cs +++ b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskFileSelector.cs @@ -94,7 +94,7 @@ namespace BizHawk.Client.EmuHawk return; } - using ArchiveChooser ac = new(new(hawkPath)); //TODO can we pass hf here instead of instantiating a new HawkFile? + using ArchiveChooser ac = new(hf); if (!this.ShowDialogAsChild(ac).IsOk() || ac.SelectedMemberIndex < 0 || hf.ArchiveItems.Count <= ac.SelectedMemberIndex) {