diff --git a/src/userprog/process.c b/src/userprog/process.c index 5c0b356..efc0f45 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -40,8 +40,6 @@ struct arg_elem that executes process_start for the purpose of starting a user process. */ struct process_start_data { - char *cmd; /* Pointer to a copy of the command used to execute the process. - Allocated a page that must be freed by process_start. */ char *cmd_saveptr; /* Value pointed to by 'saveptr' argument used by successive calls to strtok_r to split 'cmd' into tokens while maintaining state. */ @@ -90,26 +88,22 @@ process_execute (const char *cmd) /* Create a new thread to execute the command, by initializing it running the function 'start_process' with the appropriate arguments. For details of arguments, see 'start_process'. */ - data.cmd = cmd_copy; strlcpy (data.file_name, file_name, FNAME_MAX_LEN + 1); sema_init (&data.loaded, 0); data.success = false; tid = thread_create (file_name, PRI_DEFAULT, start_process, &data); - /* Return TID_ERROR and free resources if starting execution went wrong. */ - if (tid == TID_ERROR) - palloc_free_page (cmd_copy); - else + /* Wait until process file has finished attempting to load via the child + thread before reporting success of starting execution. */ + if (tid != TID_ERROR) { - - /* Wait until process file has finished attempting to load via the child - thread before reporting success of starting execution. */ sema_down (&data.loaded); if (!data.success) tid = TID_ERROR; } + palloc_free_page (cmd_copy); return tid; } @@ -158,7 +152,6 @@ start_process (void *proc_start_data) /* If load failed, quit. */ if (!data->success) { - palloc_free_page (data->cmd); sema_up (&data->loaded); thread_exit (); } @@ -167,7 +160,6 @@ start_process (void *proc_start_data) command that executed the process. */ data->success = process_init_stack (data->cmd_saveptr, &if_.esp, data->file_name); bool success = data->success; - palloc_free_page (data->cmd); sema_up (&data->loaded); /* If stack initialization failed, free resources and quit. */