Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a memory leak in chord
[simgrid.git] / examples / msg / chord / chord.c
index f8ae33b..082a555 100644 (file)
@@ -272,7 +272,7 @@ int node(int argc, char *argv[])
   double next_check_predecessor_date = init_time + periodic_check_predecessor_delay;
   double next_lookup_date = init_time + periodic_lookup_delay;
 
-  xbt_assert0(argc == 3 || argc == 5, "Wrong number of arguments for this node");
+  xbt_assert(argc == 3 || argc == 5, "Wrong number of arguments for this node");
 
   // initialize my node
   s_node_t node = {0};
@@ -349,6 +349,7 @@ int node(int argc, char *argv[])
 
         if (status != MSG_OK) {
           XBT_DEBUG("Failed to receive a task. Nevermind.");
+          MSG_comm_destroy(node.comm_receive);
           node.comm_receive = NULL;
         }
         else {
@@ -358,35 +359,12 @@ int node(int argc, char *argv[])
           handle_task(&node, task_received);
         }
       }
-
-      // see if some communications are finished
-      /*
-      while ((index = MSG_comm_testany(node.comms)) != -1) {
-        comm_send = xbt_dynar_get_as(node.comms, index, msg_comm_t);
-        MSG_error_t status = MSG_comm_get_status(comm_send);
-        xbt_dynar_remove_at(node.comms, index, &comm_send);
-        XBT_DEBUG("Communication %p is finished with status %d, dynar size is now %lu",
-            comm_send, status, xbt_dynar_length(node.comms));
-       m_task_t task = MSG_comm_get_task(comm_send);
-        MSG_comm_destroy(comm_send);
-       if (status != MSG_OK) {
-         task_data_destroy(MSG_task_get_data(task));
-         MSG_task_destroy(task);
-       }
-      }
-      */
     }
 
-    // clean unfinished comms sent
-   /* unsigned int cursor;
-    xbt_dynar_foreach(node.comms, cursor, comm_send) {
-      m_task_t task = MSG_comm_get_task(comm_send);
-      MSG_task_cancel(task);
-      task_data_destroy(MSG_task_get_data(task));
-      MSG_task_destroy(task);
-      MSG_comm_destroy(comm_send);
-      // FIXME: the task is actually not destroyed because MSG thinks that the other side (whose process is dead) is still using it
-    }*/
+    if (node.comm_receive) {
+      MSG_comm_destroy(node.comm_receive);
+      node.comm_receive = NULL;
+    }
 
     // leave the ring
     leave(&node);
@@ -394,7 +372,6 @@ int node(int argc, char *argv[])
 
   // stop the simulation
   xbt_free(node.fingers);
-  XBT_INFO("Messages created: %lu", smx_total_comms);
   return 0;
 }
 
@@ -891,8 +868,6 @@ static void random_lookup(node_t node)
  */
 int main(int argc, char *argv[])
 {
-  xbt_os_timer_t timer = xbt_os_timer_new();
-
   if (argc < 3) {
     printf("Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n", argv[0]);
     printf("example: %s ../msg_platform.xml chord.xml\n", argv[0]);
@@ -917,7 +892,7 @@ int main(int argc, char *argv[])
        XBT_DEBUG("Set timeout to %d", timeout);
       }
       else {
-       xbt_die(bprintf("Invalid chord option '%s'", options[0]));
+       xbt_die("Invalid chord option '%s'", options[0]);
       }
     }
     options++;
@@ -934,10 +909,8 @@ int main(int argc, char *argv[])
   MSG_function_register("node", node);
   MSG_launch_application(application_file);
 
-  xbt_os_timer_start(timer);
   MSG_error_t res = MSG_main();
-  xbt_os_timer_stop(timer);
-  XBT_CRITICAL("Simulation time %lf", xbt_os_timer_elapsed(timer));
+  XBT_CRITICAL("Messages created: %ld", smx_total_comms);
   XBT_INFO("Simulated time: %g", MSG_get_clock());
 
   MSG_clean();