Skip to content

Commit

Permalink
service/debugger: close executable file (#2976)
Browse files Browse the repository at this point in the history
Close executable file after we open it.
  • Loading branch information
aarzilli authored Apr 26, 2022
1 parent c120db3 commit 7ab33ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions service/debugger/debugger_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ func verifyBinaryFormat(exePath string) error {
}

// check that the binary format is what we expect for the host system
var exe interface{ Close() error }
switch runtime.GOOS {
case "darwin":
_, err = macho.NewFile(f)
exe, err = macho.NewFile(f)
case "linux", "freebsd":
_, err = elf.NewFile(f)
exe, err = elf.NewFile(f)
default:
panic("attempting to open file Delve cannot parse")
}
if err != nil {
return api.ErrNotExecutable
}
exe.Close()
return nil
}
4 changes: 3 additions & 1 deletion service/debugger/debugger_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ func verifyBinaryFormat(exePath string) error {
}
}

if _, err = pe.NewFile(f); err != nil {
exe, err := pe.NewFile(f)
if err != nil {
return api.ErrNotExecutable
}
exe.Close()
return nil
}

0 comments on commit 7ab33ac

Please sign in to comment.