Skip to content

Commit

Permalink
Merge pull request #8343 from alrs/builder-vmware-common-err-before-c…
Browse files Browse the repository at this point in the history
…lose

builder/vmware/common: defer close after testing for errors
  • Loading branch information
azr authored Nov 7, 2019
2 parents a13b61a + 5f02150 commit d4a58f5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builder/vmware/common/driver_esx5.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down

0 comments on commit d4a58f5

Please sign in to comment.