From 0305b0abe4ada656462d575a5e0f0618b42def2d Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Tue, 23 Apr 2024 14:35:09 +0200 Subject: VFS: Fix reference count of file descriptors. It appears that there was a race condition where the process got closed before the server accepted the incoming request. Causing the file descriptor to have "0" in the reference count but it would still be given when calling accept. --- kernel/socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'kernel/socket.c') diff --git a/kernel/socket.c b/kernel/socket.c index 589d99a..d24e39c 100644 --- a/kernel/socket.c +++ b/kernel/socket.c @@ -240,7 +240,8 @@ int uds_open(const char *path) { s->ptr_socket_fd->inode->has_data = 1; s->incoming_fd = get_vfs_fd(fd[1], NULL); - // vfs_close(fd[1]); + s->incoming_fd->reference_count++; + vfs_close(fd[1]); return fd[0]; } @@ -263,7 +264,7 @@ int accept(int socket, struct sockaddr *address, socklen_t *address_len) { int index; assert(list_add(¤t_task->file_descriptors, s->incoming_fd, &index)); - s->incoming_fd->reference_count++; + assert(1 <= s->incoming_fd->reference_count); s->incoming_fd = NULL; // for (char c; 0 < vfs_pread(s->fifo_fd, &c, 1, 0);) // ; -- cgit v1.2.3