[PATCH 2/3] alfred: dlose the client socket on unix_sock_req_data errors
Sven Eckelmann <[email protected]> Fri, 31 Jul 2026 08:44:20 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
By the time unix_sock_req_data() runs, the accepted client socket has
already been detached from its struct unix_client and removed from the
epoll set; each request handler owns the fd and is expected to close it on
every exit path. Two error returns did not: a request whose header.length
differs from the expected size, and a failed transaction_add(). Both
returned -1 without closing client_sock, leaking one file descriptor each.
Fixes: 5b8c4d4ad44f ("alfred: Don't block server when waiting for master reply")
Signed-off-by: Sven Eckelmann <[email protected]>
---
unix_sock.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/unix_sock.c b/unix_sock.c
index 07552a2..b93feb3 100644
--- a/unix_sock.c
+++ b/unix_sock.c
@@ -263,7 +263,7 @@ static int unix_sock_req_data(struct globals *globals,
len = ntohs(request->header.length);
if (len != (sizeof(*request) - sizeof(request->header)))
- return -1;
+ goto err;
id = ntohs(request->tx_id);
@@ -281,7 +281,7 @@ static int unix_sock_req_data(struct globals *globals,
head = transaction_add(globals, globals->best_server->hwaddr, id);
if (!head)
- return -1;
+ goto err;
head->client_socket = client_sock;
head->requested_type = request->requested_type;
@@ -290,6 +290,9 @@ static int unix_sock_req_data(struct globals *globals,
request, sizeof(*request));
return 0;
+err:
+ close(client_sock);
+ return -1;
}
int unix_sock_req_data_finish(struct globals *globals,
--
2.47.3