service/debugger: close executable file (#2976)

Close executable file after we open it.
This commit is contained in:
Alessandro Arzilli
2022-04-26 23:32:22 +02:00
committed by GitHub
parent c120db3467
commit 7ab33ac92f
2 changed files with 7 additions and 3 deletions

View File

@ -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
}

View File

@ -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
}