Fix Bug: Free all entries in the fd hashtable when the process exits, w/ E

This commit is contained in:
sBubshait
2024-11-13 17:42:25 +00:00
parent d890c2353e
commit 4f586bb4da
3 changed files with 20 additions and 0 deletions

View File

@@ -381,6 +381,20 @@ fd_less (const struct hash_elem *a_, const struct hash_elem *b_,
return a->fd < b->fd;
}
/* Function to clean up an open file entry. Closes the file and frees the
associated memory. */
void
fd_cleanup (struct hash_elem *e, void *aux UNUSED)
{
struct open_file *file_info = hash_entry (e, struct open_file, elem);
lock_acquire (&filesys_lock);
file_close (file_info->file);
lock_release (&filesys_lock);
free (file_info);
}
/* Gets a file from its descriptor (FD number). If there is no file with the fd
FD it returns NULL. */
static struct open_file *