summaryrefslogtreecommitdiff
path: root/kernel/fs/tmpfs.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-23 14:35:09 +0200
committerAnton Kling <anton@kling.gg>2024-04-23 14:35:09 +0200
commit0305b0abe4ada656462d575a5e0f0618b42def2d (patch)
treeecffe02ac3670457ed2cf0fbb513efbb69867d01 /kernel/fs/tmpfs.c
parent33663539c2bac856cf2abe79e815ad179dffecdf (diff)
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.
Diffstat (limited to 'kernel/fs/tmpfs.c')
-rw-r--r--kernel/fs/tmpfs.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/kernel/fs/tmpfs.c b/kernel/fs/tmpfs.c
index e31a08e..3ef774c 100644
--- a/kernel/fs/tmpfs.c
+++ b/kernel/fs/tmpfs.c
@@ -58,12 +58,15 @@ void dual_pipe(int fd[2]) {
vfs_create_fd(O_RDWR | O_NONBLOCK, 0, 0 /*is_tty*/, inode, &fd_ptrs[i]);
assert(-1 != fd[i]);
}
+
vfs_inode_t *f_inode = fd_ptrs[0]->inode;
vfs_inode_t *s_inode = fd_ptrs[1]->inode;
tmp_inode *f_pipe = f_inode->internal_object;
tmp_inode *s_pipe = s_inode->internal_object;
f_pipe->read_inode = s_inode;
+ s_inode->ref++;
s_pipe->read_inode = f_inode;
+ f_inode->ref++;
f_pipe->is_closed = 0;
s_pipe->is_closed = 0;
}
@@ -89,12 +92,15 @@ void pipe(int fd[2]) {
fd[i] = vfs_create_fd(O_RDWR, 0, 0 /*is_tty*/, inode, &fd_ptrs[i]);
assert(-1 != fd[i]);
}
+
vfs_inode_t *f_inode = fd_ptrs[0]->inode;
vfs_inode_t *s_inode = fd_ptrs[1]->inode;
tmp_inode *f_pipe = f_inode->internal_object;
tmp_inode *s_pipe = s_inode->internal_object;
f_pipe->read_inode = s_inode;
+ s_inode->ref++;
s_pipe->read_inode = f_inode;
+ f_inode->ref++;
f_pipe->is_closed = 0;
s_pipe->is_closed = 0;
}