From 2a326b5172894be5739d5f8a4a5b9844fbd501ff Mon Sep 17 00:00:00 2001
From: Matthew Hooker <mwhooker@gmail.com>
Date: Thu, 5 Oct 2017 16:34:13 -0700
Subject: [PATCH] fix nil ptr exception

---
 builder/vmware/iso/driver_esx5.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go
index ea93b400c..86ddf015b 100644
--- a/builder/vmware/iso/driver_esx5.go
+++ b/builder/vmware/iso/driver_esx5.go
@@ -165,10 +165,10 @@ func (d *ESX5Driver) Verify() error {
 
 func (d *ESX5Driver) HostIP() (string, error) {
 	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.LocalAddr().String())
 	return host, err