Merge branch 'stack-init-memfix' into 'master'
Fix memory leak in start_process See merge request lab2425_autumn/pintos_22!42
This commit is contained in:
@@ -40,8 +40,6 @@ struct arg_elem
|
|||||||
that executes process_start for the purpose of starting a user process. */
|
that executes process_start for the purpose of starting a user process. */
|
||||||
struct process_start_data
|
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
|
char *cmd_saveptr; /* Value pointed to by 'saveptr' argument used by
|
||||||
successive calls to strtok_r to split 'cmd' into
|
successive calls to strtok_r to split 'cmd' into
|
||||||
tokens while maintaining state. */
|
tokens while maintaining state. */
|
||||||
@@ -90,26 +88,22 @@ process_execute (const char *cmd)
|
|||||||
/* Create a new thread to execute the command, by initializing
|
/* Create a new thread to execute the command, by initializing
|
||||||
it running the function 'start_process' with the appropriate
|
it running the function 'start_process' with the appropriate
|
||||||
arguments. For details of arguments, see 'start_process'. */
|
arguments. For details of arguments, see 'start_process'. */
|
||||||
data.cmd = cmd_copy;
|
|
||||||
strlcpy (data.file_name, file_name, FNAME_MAX_LEN + 1);
|
strlcpy (data.file_name, file_name, FNAME_MAX_LEN + 1);
|
||||||
sema_init (&data.loaded, 0);
|
sema_init (&data.loaded, 0);
|
||||||
data.success = false;
|
data.success = false;
|
||||||
|
|
||||||
tid = thread_create (file_name, PRI_DEFAULT, start_process, &data);
|
tid = thread_create (file_name, PRI_DEFAULT, start_process, &data);
|
||||||
|
|
||||||
/* Return TID_ERROR and free resources if starting execution went wrong. */
|
/* Wait until process file has finished attempting to load via the child
|
||||||
if (tid == TID_ERROR)
|
thread before reporting success of starting execution. */
|
||||||
palloc_free_page (cmd_copy);
|
if (tid != TID_ERROR)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Wait until process file has finished attempting to load via the child
|
|
||||||
thread before reporting success of starting execution. */
|
|
||||||
sema_down (&data.loaded);
|
sema_down (&data.loaded);
|
||||||
if (!data.success)
|
if (!data.success)
|
||||||
tid = TID_ERROR;
|
tid = TID_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
palloc_free_page (cmd_copy);
|
||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +152,6 @@ start_process (void *proc_start_data)
|
|||||||
/* If load failed, quit. */
|
/* If load failed, quit. */
|
||||||
if (!data->success)
|
if (!data->success)
|
||||||
{
|
{
|
||||||
palloc_free_page (data->cmd);
|
|
||||||
sema_up (&data->loaded);
|
sema_up (&data->loaded);
|
||||||
thread_exit ();
|
thread_exit ();
|
||||||
}
|
}
|
||||||
@@ -167,7 +160,6 @@ start_process (void *proc_start_data)
|
|||||||
command that executed the process. */
|
command that executed the process. */
|
||||||
data->success = process_init_stack (data->cmd_saveptr, &if_.esp, data->file_name);
|
data->success = process_init_stack (data->cmd_saveptr, &if_.esp, data->file_name);
|
||||||
bool success = data->success;
|
bool success = data->success;
|
||||||
palloc_free_page (data->cmd);
|
|
||||||
sema_up (&data->loaded);
|
sema_up (&data->loaded);
|
||||||
|
|
||||||
/* If stack initialization failed, free resources and quit. */
|
/* If stack initialization failed, free resources and quit. */
|
||||||
|
|||||||
Reference in New Issue
Block a user