diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2024-10-08 21:01:57 +0200 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2024-10-08 21:01:57 +0200 |
| commit | d8af35f01e71ba1c711cd6d6c5fe0a43116c29f0 (patch) | |
| tree | fe2cfa069697063d9beed65b472c3edc16d3c55b | |
| parent | b839d06ac84f193252d5f3e5e76c432f623211bd (diff) | |
net: fix leaking sockets in dial_tcp if connect errors
| -rw-r--r-- | core/net/socket_darwin.odin | 4 | ||||
| -rw-r--r-- | core/net/socket_freebsd.odin | 4 | ||||
| -rw-r--r-- | core/net/socket_linux.odin | 3 | ||||
| -rw-r--r-- | core/net/socket_windows.odin | 4 |
4 files changed, 8 insertions, 7 deletions
diff --git a/core/net/socket_darwin.odin b/core/net/socket_darwin.odin index ec9255c3b..e26c7407d 100644 --- a/core/net/socket_darwin.odin +++ b/core/net/socket_darwin.odin @@ -88,8 +88,8 @@ _dial_tcp_from_endpoint :: proc(endpoint: Endpoint, options := default_tcp_optio sockaddr := _endpoint_to_sockaddr(endpoint) res := os.connect(os.Socket(skt), (^os.SOCKADDR)(&sockaddr), i32(sockaddr.len)) if res != nil { - err = Dial_Error(os.is_platform_error(res) or_else -1) - return + close(skt) + return {}, Dial_Error(os.is_platform_error(res) or_else -1) } return diff --git a/core/net/socket_freebsd.odin b/core/net/socket_freebsd.odin index 0f3a85cbb..2c193b0d8 100644 --- a/core/net/socket_freebsd.odin +++ b/core/net/socket_freebsd.odin @@ -114,8 +114,8 @@ _dial_tcp_from_endpoint :: proc(endpoint: Endpoint, options := default_tcp_optio sockaddr := _endpoint_to_sockaddr(endpoint) errno := freebsd.connect(cast(Fd)socket, &sockaddr, cast(freebsd.socklen_t)sockaddr.len) if errno != nil { - err = cast(Dial_Error)errno - return + close(socket) + return {}, cast(Dial_Error)errno } return diff --git a/core/net/socket_linux.odin b/core/net/socket_linux.odin index a3853874a..be189f5c1 100644 --- a/core/net/socket_linux.odin +++ b/core/net/socket_linux.odin @@ -147,7 +147,8 @@ _dial_tcp_from_endpoint :: proc(endpoint: Endpoint, options := default_tcp_optio addr := _unwrap_os_addr(endpoint) errno = linux.connect(linux.Fd(os_sock), &addr) if errno != .NONE { - return cast(TCP_Socket) os_sock, Dial_Error(errno) + close(cast(TCP_Socket) os_sock) + return {}, Dial_Error(errno) } // NOTE(tetra): Not vital to succeed; error ignored no_delay: b32 = cast(b32) options.no_delay diff --git a/core/net/socket_windows.odin b/core/net/socket_windows.odin index 20f17619d..8e18f4f88 100644 --- a/core/net/socket_windows.odin +++ b/core/net/socket_windows.odin @@ -80,8 +80,8 @@ _dial_tcp_from_endpoint :: proc(endpoint: Endpoint, options := default_tcp_optio sockaddr := _endpoint_to_sockaddr(endpoint) res := win.connect(win.SOCKET(socket), &sockaddr, size_of(sockaddr)) if res < 0 { - err = Dial_Error(win.WSAGetLastError()) - return + close(socket) + return {}, Dial_Error(win.WSAGetLastError()) } if options.no_delay { |