Merge pull request #8343 from alrs/builder-vmware-common-err-before-close

builder/vmware/common: defer close after testing for errors
This commit is contained in:
Adrien Delorme 2019-11-07 10:28:13 +01:00 committed by GitHub
commit d4a58f59e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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())