Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix memory leaks in msg/icomms examples.
authoragiersch <agiersch@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 15 Nov 2010 17:11:09 +0000 (17:11 +0000)
committeragiersch <agiersch@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 15 Nov 2010 17:11:09 +0000 (17:11 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8555 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/msg/icomms/peer2.c
examples/msg/icomms/peer3.c

index 6a0d0fc..d5d7c95 100644 (file)
@@ -28,8 +28,7 @@ int sender(int argc, char *argv[])
   double task_comm_size = atof(argv[3]);
   long receivers_count = atol(argv[4]);
 
-  msg_comm_t *comm =
-      malloc((number_of_tasks + receivers_count) * sizeof(msg_comm_t));
+  msg_comm_t *comm = xbt_new(msg_comm_t, number_of_tasks + receivers_count);
   int i;
   m_task_t task = NULL;
   for (i = 0; i < number_of_tasks; i++) {
@@ -55,6 +54,7 @@ int sender(int argc, char *argv[])
   MSG_comm_waitall(comm, (number_of_tasks + receivers_count), -1);
 
   INFO0("Goodbye now!");
+  xbt_free(comm);
   return 0;
 }                               /* end_of_sender */
 
index feba87d..93e933c 100644 (file)
@@ -35,8 +35,7 @@ int sender(int argc, char *argv[])
   char mailbox[256];
   char sprintf_buffer[256];
   d = xbt_dynar_new(sizeof(msg_comm_t), NULL);
-  msg_comm_t *comm =
-      malloc((number_of_tasks + receivers_count) * sizeof(msg_comm_t));
+  msg_comm_t *comm = xbt_new(msg_comm_t, number_of_tasks + receivers_count);
   msg_comm_t res_irecv = NULL;
   for (i = 0; i < (number_of_tasks); i++) {
     task = NULL;
@@ -51,7 +50,6 @@ int sender(int argc, char *argv[])
         MSG_task_create(sprintf_buffer, task_comp_size,
                         task_comm_size / coef, NULL);
     comm[i] = MSG_task_isend(task, mailbox);
-    MSG_task_refcount_dec(task);
     xbt_dynar_push_as(d, msg_comm_t, comm[i]);
     INFO3("Send to receiver-%ld %s comm_size %f", i % receivers_count,
           sprintf_buffer, task_comm_size / coef);
@@ -60,9 +58,10 @@ int sender(int argc, char *argv[])
 
   while (d->used) {
     xbt_dynar_remove_at(d, MSG_comm_waitany(d), &res_irecv);
+    MSG_comm_destroy(res_irecv);
   }
   xbt_dynar_free(&d);
-
+  xbt_free(comm);
 
   /* Here we are waiting for the completion of all tasks */
   sprintf(mailbox, "finalize");
@@ -113,6 +112,7 @@ int receiver(int argc, char *argv[])
     int num = MSG_comm_waitany(comms);
     xbt_dynar_remove_at(comms, num, &res_irecv);
     task_com = MSG_comm_get_task(res_irecv);
+    MSG_comm_destroy(res_irecv);
     INFO1("Processing \"%s\"", MSG_task_get_name(task_com));
     MSG_task_execute(task_com);
     INFO1("\"%s\" done", MSG_task_get_name(task_com));