Skip to content

Commit aa22ad2

Browse files
committed
fs: close files that get dup'd over
1 parent 4ae96ca commit aa22ad2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/fs/file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ int add_file(struct file *file) {
104104

105105
int add_file_at(struct file *file, int at) {
106106
file->magic = FILE_MAGIC;
107-
dmgr_set(&running_process->fds, at, file);
107+
struct file *old = dmgr_set(&running_process->fds, at, file);
108+
if (old)
109+
close_file(old);
108110

109111
return at;
110112
}

0 commit comments

Comments
 (0)