From cfd83ccc1e4ea4cf442bf65ac22d55caf5cb3910 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 27 Nov 2023 13:16:34 +0100 Subject: [PATCH] server: properly handle unclaimed file descriptors Signed-off-by: Felix Fietkau --- client.c | 7 +++++++ ring.c | 1 + 2 files changed, 8 insertions(+) diff --git a/client.c b/client.c index 11d1c52..93f3195 100644 --- a/client.c +++ b/client.c @@ -199,6 +199,12 @@ static void client_parse_message(struct client *cl) DC(3, cl, "Invalid message type %d", msg->type); break; } + + if (cl->rx_fd < 0) + return; + + close(cl->rx_fd); + cl->rx_fd = -1; } static void client_fd_cb(struct uloop_fd *fd, unsigned int events) @@ -225,6 +231,7 @@ static void client_fd_cb(struct uloop_fd *fd, unsigned int events) msg.msg_controllen = cmsg->cmsg_len; retry: + *pfd = -1; if (fd->eof) { client_free(cl); return; diff --git a/ring.c b/ring.c index 8a7e27f..81f341f 100644 --- a/ring.c +++ b/ring.c @@ -64,6 +64,7 @@ struct client_ring *client_ring_alloc(struct client *cl) r->cl = cl; r->id = msg->id; r->fd = cl->rx_fd; + cl->rx_fd = -1; r->ring_size = msg->ring_size; r->data_size = msg->data_size; list_add_tail(&r->list, &cl->bufs); -- 2.30.2