From 5f02150e0590b6bf167c1d7e3f1d691017c5f715 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 6 Nov 2019 14:28:17 -0800 Subject: [PATCH] builder/vmware/common: defer close after testing for errors --- builder/vmware/common/driver_esx5.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/vmware/common/driver_esx5.go b/builder/vmware/common/driver_esx5.go index 8b4ac8987..109b91967 100644 --- a/builder/vmware/common/driver_esx5.go +++ b/builder/vmware/common/driver_esx5.go @@ -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())