From ca9d23edf9186b8c6e6650946d722301d8795e1f Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Tue, 12 Nov 2024 20:07:51 +0000 Subject: [PATCH] Always release filesys_lock when checking if file is valid in process_execute --- src/userprog/process.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/userprog/process.c b/src/userprog/process.c index 4d0c1ca..ac0cc39 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -82,14 +82,15 @@ process_execute (const char *cmd) of the process. */ char *file_name = strtok_r (cmd_copy, " ", &data->cmd_saveptr); -/* NOTE: Currently, the file being executed is closed in load () and then + /* NOTE: Currently, the file being executed is closed in load () and then reopened here. Because load is an exported public function, this might be necessary. */ lock_acquire (&filesys_lock); /* Validates that the current file to be executed is a valid file */ - if (filesys_open (file_name) == NULL) - return TID_ERROR; + bool valid_file = filesys_open (file_name) != NULL; lock_release (&filesys_lock); + if (!valid_file) + return TID_ERROR; /* Create a new thread to execute the command, by initializing it running the function 'start_process' with the appropriate