Skip to content

Commit

Permalink
Don't dispose hawkfile stream after ReadAllBytes(), fix ReadAllBytes …
Browse files Browse the repository at this point in the history
…callsites to do disposal properly
  • Loading branch information
CasualPokePlayer committed Jan 10, 2025
1 parent 4aa3342 commit a30c0ef
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/RomLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ public bool LoadRom(string path, CoreComm nextComm, string launchLibretroCore, s
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 */}]";
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/movie/import/IMovieImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private string PromptForRom(MatchesMovieHash matchesMovieHash)

using var rom = new HawkFile(result);
if (rom.IsArchive) rom.BindFirst();
var romData = (ReadOnlySpan<byte>) rom.ReadAllBytes();
var romData = new ReadOnlySpan<byte>(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))
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private void TsmiSetCustomization_Click(object sender, EventArgs e)
// 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);
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void SetPaletteImage()
{
if (PalettePath.Text.Length > 0)
{
var palette = new HawkFile(PalettePath.Text);
using var palette = new HawkFile(PalettePath.Text);

if (palette.Exists)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void ButtonPal_Click(object sender, EventArgs e)
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void BrowseButton_Click(object sender, EventArgs e)
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)
{
Expand Down

2 comments on commit a30c0ef

@Morilli
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something? Where is the ReadAllBytes dispose change in here?

@CasualPokePlayer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently I missed that when adding files for commit.

Please sign in to comment.