From: Remi Tricot-Le Breton Date: Thu, 14 Jan 2021 14:26:24 +0000 (+0100) Subject: BUG/MINOR: sock: Unclosed fd in case of connection allocation failure X-Git-Tag: v2.4-dev7~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25dd0ad1239627aa87d9ce25d268546037a97197;p=thirdparty%2Fhaproxy.git BUG/MINOR: sock: Unclosed fd in case of connection allocation failure If allocating a connection object failed right after a successful accept on a listener, the new file descriptor was not properly closed. This fixes GitHub issue #905. It can be backported to 2.3. --- diff --git a/src/sock.c b/src/sock.c index 20ebdd0e4e..596be43d6c 100644 --- a/src/sock.c +++ b/src/sock.c @@ -161,6 +161,9 @@ struct connection *sock_accept_conn(struct listener *l, int *status) fail_conn: sockaddr_free(&addr); + /* The accept call already succeeded by the time we try to allocate the connection, + * we need to close it in case of failure. */ + close(cfd); fail_addr: ret = CO_AC_PAUSE; goto done;