From 8c5865d4e7fee89c71108808dc65f44034f2d1d3 Mon Sep 17 00:00:00 2001
From: V2Ray <admin@v2ray.com>
Date: Tue, 13 Oct 2015 22:00:03 +0200
Subject: [PATCH] Lazy initialize of socks5 response

---
 proxy/socks/socks.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proxy/socks/socks.go b/proxy/socks/socks.go
index 35d8001e..113a4cdf 100644
--- a/proxy/socks/socks.go
+++ b/proxy/socks/socks.go
@@ -134,7 +134,6 @@ func (server *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.W
 		return server.handleUDP(reader, writer)
 	}
 
-	response := protocol.NewSocks5Response()
 	if request.Command == protocol.CmdBind || request.Command == protocol.CmdUdpAssociate {
 		response := protocol.NewSocks5Response()
 		response.Error = protocol.ErrorCommandNotSupported
@@ -151,6 +150,7 @@ func (server *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.W
 		return UnsupportedSocksCommand
 	}
 
+  response := protocol.NewSocks5Response()
 	response.Error = protocol.ErrorSuccess
 
 	// Some SOCKS software requires a value other than dest. Let's fake one: