mirror of
https://github.com/golang/go
synced 2024-11-14 22:30:26 -07:00
cmd/cgo: close the file opened in the dynimport function
Change-Id: Ic457e994b50a0e8c1769311937eede1e710a1293
GitHub-Last-Rev: a8af7b5e67
GitHub-Pull-Request: golang/go#66549
Reviewed-on: https://go-review.googlesource.com/c/go/+/574537
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
d0051be847
commit
8f59b28fb3
@ -335,12 +335,19 @@ func dynimport(obj string) {
|
||||
if err != nil {
|
||||
fatalf("%s", err)
|
||||
}
|
||||
defer func() {
|
||||
if err = f.Close(); err != nil {
|
||||
fatalf("error closing %s: %v", *dynout, err)
|
||||
}
|
||||
}()
|
||||
|
||||
stdout = f
|
||||
}
|
||||
|
||||
fmt.Fprintf(stdout, "package %s\n", *dynpackage)
|
||||
|
||||
if f, err := elf.Open(obj); err == nil {
|
||||
defer f.Close()
|
||||
if *dynlinker {
|
||||
// Emit the cgo_dynamic_linker line.
|
||||
if sec := f.Section(".interp"); sec != nil {
|
||||
@ -368,6 +375,7 @@ func dynimport(obj string) {
|
||||
}
|
||||
|
||||
if f, err := macho.Open(obj); err == nil {
|
||||
defer f.Close()
|
||||
sym, _ := f.ImportedSymbols()
|
||||
for _, s := range sym {
|
||||
if len(s) > 0 && s[0] == '_' {
|
||||
@ -384,6 +392,7 @@ func dynimport(obj string) {
|
||||
}
|
||||
|
||||
if f, err := pe.Open(obj); err == nil {
|
||||
defer f.Close()
|
||||
sym, _ := f.ImportedSymbols()
|
||||
for _, s := range sym {
|
||||
ss := strings.Split(s, ":")
|
||||
@ -396,6 +405,7 @@ func dynimport(obj string) {
|
||||
}
|
||||
|
||||
if f, err := xcoff.Open(obj); err == nil {
|
||||
defer f.Close()
|
||||
sym, err := f.ImportedSymbols()
|
||||
if err != nil {
|
||||
fatalf("cannot load imported symbols from XCOFF file %s: %v", obj, err)
|
||||
|
Loading…
Reference in New Issue
Block a user