fix: memory leakage in file descriptor allocation
[lunaix-os.git] / lunaix-os / kernel / process / sched.c
index 4e3f290c4ca61e36699988c9f77f899d567c3bf7..c2a24261dde6c7dc92eba8285b37368209c9a457 100644 (file)
@@ -172,7 +172,8 @@ __DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
     llist_append(&root_proc->sleep.sleepers, &__current->sleep.sleepers);
 
     __current->intr_ctx.registers.eax = seconds;
     llist_append(&root_proc->sleep.sleepers, &__current->sleep.sleepers);
 
     __current->intr_ctx.registers.eax = seconds;
-    __current->state = PS_BLOCKED;
+
+    block_current();
     schedule();
 }
 
     schedule();
 }
 
@@ -346,8 +347,10 @@ destroy_process(pid_t pid)
 
     for (size_t i = 0; i < VFS_MAX_FD; i++) {
         struct v_fd* fd = proc->fdtable->fds[i];
 
     for (size_t i = 0; i < VFS_MAX_FD; i++) {
         struct v_fd* fd = proc->fdtable->fds[i];
-        if (fd)
+        if (fd) {
             vfs_pclose(fd->file, pid);
             vfs_pclose(fd->file, pid);
+            vfs_free_fd(fd);
+        }
     }
 
     vfree(proc->fdtable);
     }
 
     vfree(proc->fdtable);