From: William Lallemand Date: Fri, 29 Sep 2023 22:53:43 +0000 (+0200) Subject: BUG/MINOR: proto_reverse_connect: fix FD leak upon connect X-Git-Tag: v2.9-dev7~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c21ec3b7351c49e6bc6a49983d59701377c75d9b;p=thirdparty%2Fhaproxy.git BUG/MINOR: proto_reverse_connect: fix FD leak upon connect new_reverse_conn() is creating its own socket with sock_create_server_socket(). However the connect is done with conn->ctrl->connect() which is tcp_connect_server(). tcp_connect_server() is also creating its own socket and sets it in the struct conn, left the previous socket unclosed and leaking at each attempt. This patch fixes the issue by letting tcp_connect_server() handling the socket part, and removes it in new_reverse_conn(). --- diff --git a/src/proto_reverse_connect.c b/src/proto_reverse_connect.c index 1649a69dfa..61cf448065 100644 --- a/src/proto_reverse_connect.c +++ b/src/proto_reverse_connect.c @@ -68,11 +68,6 @@ static struct connection *new_reverse_conn(struct listener *l, struct server *sr if (conn_prepare(conn, protocol_lookup(conn->dst->ss_family, PROTO_TYPE_STREAM, 0), srv->xprt)) goto err; - /* TODO simplification of tcp_connect_server() */ - conn->handle.fd = sock_create_server_socket(conn); - if (fd_set_nonblock(conn->handle.fd) == -1) - goto err; - if (conn->ctrl->connect(conn, 0) != SF_ERR_NONE) goto err;