server: properly handle unclaimed file descriptors
authorFelix Fietkau <nbd@nbd.name>
Mon, 27 Nov 2023 12:16:34 +0000 (13:16 +0100)
committerFelix Fietkau <nbd@nbd.name>
Mon, 27 Nov 2023 12:16:35 +0000 (13:16 +0100)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
client.c
ring.c

index 11d1c527c87abfce9c522f6126c63a39747fc539..93f31954f321f28eee09b8ee941991b6fe807d8e 100644 (file)
--- 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 8a7e27fc7eb5c6b7d3abbfb545ddd20be878c494..81f341f4a4bcda394b92a6641fc078bd60281ffb 100644 (file)
--- 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);