From 3e49cb01bd25759e94076296eeb0a6179d27942b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 9 Apr 2023 12:55:09 +0930 Subject: [PATCH] connectd: don't leak fds if we have both IPv4 and IPv6. We accept that we will fail to listen if we bind both IPv6 and IPv4 to the same socket on a dual-stack machine (e.g. normal Linux), but we weren't closing the fd. Signed-off-by: Rusty Russell --- connectd/connectd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/connectd/connectd.c b/connectd/connectd.c index cc71b6254..30c88440e 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -1561,8 +1561,10 @@ static void connect_activate(struct daemon *daemon, const u8 *msg) if (do_listen) { for (size_t i = 0; i < tal_count(daemon->listen_fds); i++) { if (listen(daemon->listen_fds[i]->fd, 64) != 0) { - if (daemon->listen_fds[i]->mayfail) + if (daemon->listen_fds[i]->mayfail) { + close(daemon->listen_fds[i]->fd); continue; + } errmsg = tal_fmt(tmpctx, "Failed to listen on socket %s: %s", type_to_string(tmpctx,