From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 3/4] alfred: close the listening socket on daemon setup errors
Date: Fri, 31 Jul 2026 09:40:15 +0200 [thread overview]
Message-ID: <20260731-bugfixes-client-v1-3-83d8c7a26421@narfation.org> (raw)
In-Reply-To: <20260731-bugfixes-client-v1-0-83d8c7a26421@narfation.org>
unix_sock_open_daemon() created the listening unix socket but returned -1
without closing it again when bind(), listen() or the epoll_ctl()
registration failed, leaking the descriptor.
Fixes: 23359bbf72aa ("alfred: initial commit")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
unix_sock.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/unix_sock.c b/unix_sock.c
index e24c788..d4261ba 100644
--- a/unix_sock.c
+++ b/unix_sock.c
@@ -51,12 +51,12 @@ int unix_sock_open_daemon(struct globals *globals)
if (bind(globals->unix_sock, (struct sockaddr *)&addr,
sizeof(addr)) < 0) {
perror("can't bind unix socket");
- return -1;
+ goto err;
}
if (listen(globals->unix_sock, 10) < 0) {
perror("can't listen on unix socket");
- return -1;
+ goto err;
}
ev.events = EPOLLIN;
@@ -66,10 +66,15 @@ int unix_sock_open_daemon(struct globals *globals)
if (epoll_ctl(globals->epollfd, EPOLL_CTL_ADD, globals->unix_sock,
&ev) == -1) {
perror("Failed to add epoll for check_timer");
- return -1;
+ goto err;
}
return 0;
+
+err:
+ close(globals->unix_sock);
+ globals->unix_sock = -1;
+ return -1;
}
int unix_sock_open_client(struct globals *globals)
--
2.47.3
next prev parent reply other threads:[~2026-07-31 7:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 7:40 [PATCH 0/4] alfred: client: random fixes Sven Eckelmann
2026-07-31 7:40 ` [PATCH 1/4] alfred: fix error code from unix_sock_req_data_reply Sven Eckelmann
2026-07-31 7:40 ` [PATCH 2/4] alfred: avoid endless-loop when reading data from stdin fails Sven Eckelmann
2026-07-31 7:40 ` Sven Eckelmann [this message]
2026-07-31 7:40 ` [PATCH 4/4] alfred: handle short reads when waiting for daemon answer Sven Eckelmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260731-bugfixes-client-v1-3-83d8c7a26421@narfation.org \
--to=sven@narfation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox