From 0559ac369439135372fab0951d416eafc86bd6ac Mon Sep 17 00:00:00 2001 From: JohnHAOCENG <haoczhao@student.unimelb.edu.au> Date: Sun, 28 Mar 2021 22:13:43 +0800 Subject: [PATCH] free --- allocate.c | 2 -- allocate.h | 2 +- task1.c | 1 + task2.c | 2 ++ task3.c | 11 +++++++++++ tools.c | 11 +++++++++++ 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/allocate.c b/allocate.c index ad262d9..a590410 100644 --- a/allocate.c +++ b/allocate.c @@ -36,5 +36,3 @@ int main(int argc, char *argv[]) return 0; } - - diff --git a/allocate.h b/allocate.h index d64ca5d..0f94bd7 100644 --- a/allocate.h +++ b/allocate.h @@ -61,7 +61,7 @@ void show_stat(int timer, int *turn_around_array, int *ini_exe_array, int num_pr int find_sub_process(int parallel_pro_id, process_t **cpu_queue, int queue_len); int adding_new_process(process_t **new_processes, process_t **all_process_array, int num_process, int timer, int *rest_proc); - +void free_all_process_array(process_t** all_process_array); /* task1 */ diff --git a/task1.c b/task1.c index 2d484df..a9077af 100644 --- a/task1.c +++ b/task1.c @@ -84,6 +84,7 @@ void check_finished_pro_T1(process_t *cur_processing_pro, int *rest_proc, int ti /* record information for the performance statistics*/ record_perform_info(turn_around_array, ini_exe_array, performance_index, cur_processing_pro, timer); + free(cur_processing_pro); } } diff --git a/task2.c b/task2.c index a5361ed..ab6f6a3 100644 --- a/task2.c +++ b/task2.c @@ -194,6 +194,8 @@ void processing_lst(int *finished_array_index, int *finished_array, process_t ** *finished_process += 1; } + + free(cur_processing_pro); } } diff --git a/task3.c b/task3.c index aeef235..b7cb8b6 100644 --- a/task3.c +++ b/task3.c @@ -71,6 +71,16 @@ void load_task3(process_t **all_process_array, int num_process, char *processors /* Performance statistics: */ show_stat(timer, turn_around_array, ini_exe_array, num_process); + + /* free the all_cpu_lst */ + for(int i=0; i<num_processors; i++){ + for(int j=0;j<all_cpus_lst[i]->running_lst_len;j++){ + free(all_cpus_lst[i]->cpu_running_lst[j]); + } + free(all_cpus_lst[i]->cpu_running_lst); + free(all_cpus_lst[i]); + } + free(all_cpus_lst); } /* allocate all new arrive processes to cpus */ @@ -259,6 +269,7 @@ void processing_each_cpu_lst(int *finished_process, int *rest_proc, int timer, l delete_head(cur_cpu_running_lst, &selected_cpu_lst->running_lst_len); *finished_process += 1; } + free(cur_processing_pro); } } diff --git a/tools.c b/tools.c index 34eaf49..792df64 100644 --- a/tools.c +++ b/tools.c @@ -213,3 +213,14 @@ void record_perform_info(int *turn_around_array, int *ini_exe_array, int *perfor ini_exe_array[*performance_index] = cur_processing_pro->ini_exe_time; *performance_index += 1; } + +/* free the array*/ + +void free_all_process_array(process_t** all_process_array){ + for(int i=0 ; i<PROCESS_SIZE; i++){ + free(all_process_array[i]); + } + free(all_process_array); +} + + -- GitLab