builder/vmware/common: defer close after testing for errors

This commit is contained in:
Lars Lehtonen 2019-11-06 14:28:17 -08:00
parent fdd12c4e9f
commit 5f02150e05
No known key found for this signature in database
GPG Key ID: 8137D474EBCB04F2
1 changed files with 2 additions and 2 deletions

View File

@ -268,10 +268,10 @@ func (d *ESX5Driver) HostIP(multistep.StateBag) (string, error) {
func (d *ESX5Driver) GuestIP(multistep.StateBag) (string, error) {
// GuestIP is defined by the user as d.Host..but let's validate it just to be sure
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", d.Host, d.Port))
defer conn.Close()
if err != nil {
return "", err
}
defer conn.Close()
host, _, err := net.SplitHostPort(conn.RemoteAddr().String())
return host, err
@ -280,10 +280,10 @@ func (d *ESX5Driver) GuestIP(multistep.StateBag) (string, error) {
func (d *ESX5Driver) HostAddress(multistep.StateBag) (string, error) {
// make a connection
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", d.Host, d.Port))
defer conn.Close()
if err != nil {
return "", err
}
defer conn.Close()
// get the local address (the host)
host, _, err := net.SplitHostPort(conn.LocalAddr().String())