diff --git a/allocate.c b/allocate.c index ad262d9d1730390811f7a42f577e53db0a98f2d5..a59041003913aa5827e9fe4241e70cc03ba0ca66 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 d64ca5de97b0550a52c4d95b05b012ea192f204b..0f94bd7bd4550e33ded65880f1f28d586bf221e9 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 2d484dfbbd4af2a1bdf615792f005918eeef5477..a9077afd15678bb8df13250167e50dd4bf0685cc 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 a5361edcc98bfea9420a6e007f7360ff741e5b62..ab6f6a322a5bcf31500718ee6c96bf9af55dc3b7 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 aeef23544fbb38b3be8503f581d492d62691ef9d..b7cb8b66b8a0e1a6aa2ae70aa400e9e36e41093a 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 34eaf49471c554c66e895f1223694c9266be9713..792df648e570a9792bd2ccd6e47202334ffd840c 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); +} + +