Skip to content

Commit

Permalink
additional notes: ensure to close files (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
drakkan authored Mar 6, 2023
1 parent a4df04d commit 930b2bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions notes_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ func additionalNotesAboutCommand(path string) string {
}

if elfFile, err := elf.Open(path); err == nil {
defer elfFile.Close()
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)
} else if machoFile, err := macho.Open(path); err == nil {
defer machoFile.Close()
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH)
} else if peFile, err := pe.Open(path); err == nil {
defer peFile.Close()
machine, ok := peTypes[peFile.Machine]
if !ok {
machine = "unknown"
Expand Down
3 changes: 3 additions & 0 deletions notes_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ func additionalNotesAboutCommand(path string) string {
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode())

if elfFile, err := elf.Open(path); err == nil {
defer elfFile.Close()
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)
} else if machoFile, err := macho.Open(path); err == nil {
defer machoFile.Close()
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH)
} else if peFile, err := pe.Open(path); err == nil {
defer peFile.Close()
machine, ok := peTypes[peFile.Machine]
if !ok {
machine = "unknown"
Expand Down

0 comments on commit 930b2bf

Please sign in to comment.