Don't try to close the client config file if opening fails
$ q panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x0 pc=0x9c124] goroutine 1 [running]: os.(*File).Close(0x0, 0xf800000010, 0x0, 0xf840054e40) /usr/local/go/src/pkg/os/file_unix.go:99 +0x1c github.com/miekg/dns.ClientConfigFromFile(0x1c3294, 0x6374652f00000010, 0x0, 0xf840054e40, 0xf840054de0, ...) /Users/ask/go/src/github.com/miekg/dns/clientconfig.go:30 +0xcc main.main() /Users/ask/go/src/github.com/miekg/dns/ex/q/q.go:50 +0x45b
This commit is contained in:
parent
da9a970a5e
commit
e7e56ada07
|
@ -25,10 +25,10 @@ type ClientConfig struct {
|
|||
// a *ClientConfig.
|
||||
func ClientConfigFromFile(conf string) (*ClientConfig, error) {
|
||||
file, err := os.Open(conf)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
c := new(ClientConfig)
|
||||
b := bufio.NewReader(file)
|
||||
c.Servers = make([]string, 0)
|
||||
|
|
Loading…
Reference in New Issue