diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-05-18 04:39:03 +0000 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-05-18 04:39:03 +0000 |
commit | ac42568f3cf5144c433a453d58ffe25af5284795 (patch) | |
tree | eb5c1dbcc3d9a517cda21857e5d3497c66b5d5be /server/sockopt_linux.go | |
parent | c008e48b23911145ccf4b2681386861f643c7d8c (diff) |
server: fix socket leak in DialTCPTimeoutWithMD5Sig()
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/sockopt_linux.go')
-rw-r--r-- | server/sockopt_linux.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/server/sockopt_linux.go b/server/sockopt_linux.go index 436591e9..4a68a18d 100644 --- a/server/sockopt_linux.go +++ b/server/sockopt_linux.go @@ -75,6 +75,9 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec if err != nil { return nil, err } + fi := os.NewFile(uintptr(fd), "") + defer fi.Close() + t, err := buildTcpMD5Sig(host, key) if err != nil { return nil, err @@ -94,9 +97,7 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec return nil, os.NewSyscallError("bind", err) } - tcpconn := func(fd uintptr) (*net.TCPConn, error) { - fi := os.NewFile(uintptr(fd), "") - defer fi.Close() + tcpconn := func(fi *os.File) (*net.TCPConn, error) { conn, err := net.FileConn(fi) return conn.(*net.TCPConn), err } @@ -106,7 +107,7 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR: // do timeout handling case nil, syscall.EISCONN: - return tcpconn(uintptr(fd)) + return tcpconn(fi) default: return nil, os.NewSyscallError("connect", err) } @@ -141,7 +142,7 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec switch err := syscall.Errno(nerr); err { case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR: case syscall.Errno(0), syscall.EISCONN: - return tcpconn(uintptr(fd)) + return tcpconn(fi) default: return nil, os.NewSyscallError("getsockopt", err) } |