From ba221c8370d9d092fae68858cd4004250030740e Mon Sep 17 00:00:00 2001 From: agiersch Date: Thu, 27 Jan 2011 10:52:03 +0000 Subject: [PATCH] Fix memory leaks in msg examples. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9515 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- examples/msg/parallel_task/parallel_task.c | 6 +++++- examples/msg/parallel_task/test_ptask.c | 4 ++++ examples/msg/priority/priority.c | 2 +- examples/msg/sendrecv/sendrecv.c | 2 ++ examples/msg/trace/test_trace_integration.c | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/msg/parallel_task/parallel_task.c b/examples/msg/parallel_task/parallel_task.c index 89fc1c17b4..3a3825c28f 100644 --- a/examples/msg/parallel_task/parallel_task.c +++ b/examples/msg/parallel_task/parallel_task.c @@ -48,6 +48,7 @@ int test(int argc, char *argv[]) communication_amount, NULL); MSG_parallel_task_execute(ptask); + MSG_task_destroy(ptask); /* There is no need to free that! */ /* free(communication_amount); */ /* free(computation_amount); */ @@ -61,13 +62,16 @@ int test(int argc, char *argv[]) MSG_error_t test_all(const char *platform_file) { MSG_error_t res = MSG_OK; + m_host_t *hosts; MSG_config("workstation/model", "ptask_L07"); MSG_set_channel_number(1); MSG_create_environment(platform_file); - MSG_process_create("test", test, NULL, MSG_get_host_table()[0]); + hosts = MSG_get_host_table(); + MSG_process_create("test", test, NULL, hosts[0]); res = MSG_main(); + xbt_free(hosts); INFO1("Simulation time %g", MSG_get_clock()); return res; diff --git a/examples/msg/parallel_task/test_ptask.c b/examples/msg/parallel_task/test_ptask.c index b73ab3aef4..8047d8a444 100644 --- a/examples/msg/parallel_task/test_ptask.c +++ b/examples/msg/parallel_task/test_ptask.c @@ -72,6 +72,8 @@ int execute(int argc, char *argv[]) execution_time = MSG_get_clock(); MSG_parallel_task_execute(task); + MSG_task_destroy(task); + xbt_free(m_host_list); execution_time = MSG_get_clock() - execution_time; INFO1("execution_time=%g ", execution_time); @@ -122,6 +124,8 @@ int redistribute(int argc, char *argv[]) redistribution_time = MSG_get_clock(); MSG_parallel_task_execute(task); + MSG_task_destroy(task); + xbt_free(m_host_list); redistribution_time = MSG_get_clock() - redistribution_time; INFO1("redistribution_time=%g ", redistribution_time); diff --git a/examples/msg/priority/priority.c b/examples/msg/priority/priority.c index 1a311574be..30ec3456a7 100644 --- a/examples/msg/priority/priority.c +++ b/examples/msg/priority/priority.c @@ -32,7 +32,7 @@ static int test(int argc, char *argv[]) MSG_task_set_priority(task, priority); MSG_task_execute(task); - + MSG_task_destroy(task); INFO0("Goodbye now!"); return 0; diff --git a/examples/msg/sendrecv/sendrecv.c b/examples/msg/sendrecv/sendrecv.c index d413535edb..a16f9ccab1 100644 --- a/examples/msg/sendrecv/sendrecv.c +++ b/examples/msg/sendrecv/sendrecv.c @@ -97,6 +97,7 @@ int receiver(int argc, char *argv[]) time = sender_time; communication_time = time1 - time; INFO1("Task received : %s", task_la->name); + xbt_free(task_la->data); MSG_task_destroy(task_la); INFO1("Communic. time %le", communication_time); INFO1("--- la %f ----", communication_time); @@ -113,6 +114,7 @@ int receiver(int argc, char *argv[]) time = sender_time; communication_time = time1 - time; INFO1("Task received : %s", task_bw->name); + xbt_free(task_bw->data); MSG_task_destroy(task_bw); INFO1("Communic. time %le", communication_time); INFO1("--- bw %f ----", task_comm_size_bw / communication_time); diff --git a/examples/msg/trace/test_trace_integration.c b/examples/msg/trace/test_trace_integration.c index 057810d4cf..426e1827ed 100644 --- a/examples/msg/trace/test_trace_integration.c +++ b/examples/msg/trace/test_trace_integration.c @@ -39,6 +39,7 @@ int test_trace(int argc, char *argv[]) task = MSG_task_create("proc 0", task_comp_size, 0, NULL); MSG_task_set_priority(task, task_prio); MSG_task_execute(task); + MSG_task_destroy(task); INFO0("Test finished"); -- 2.20.1