Skip to content

Commit

Permalink
BUG/MINOR: proto_reverse_connect: fix FD leak upon connect
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
wlallemand committed Sep 29, 2023
1 parent c58fd4d commit c21ec3b
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/proto_reverse_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c21ec3b

Please sign in to comment.