Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Free those variables after the end of the cluster tag.
[simgrid.git] / src / surf / surf_routing.c
index 6759694..3428327 100644 (file)
@@ -25,7 +25,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
 routing_global_t global_routing = NULL;
 routing_component_t current_routing = NULL;
 model_type_t current_routing_model = NULL;
-static double_f_pvoid_t get_link_latency = NULL;
+static double_f_cpvoid_t get_link_latency = NULL;
 
 /* Prototypes of each model */
 static void *model_full_create(void);   /* create structures for full routing model */
@@ -243,7 +243,7 @@ static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_
 }
 
 /**
- * \breif Set the endpoints for a route from XML
+ * \brief Set the endpoints for a route from XML
  */
 static void parse_S_route_new_and_endpoints_XML(void)
 {
@@ -252,7 +252,7 @@ static void parse_S_route_new_and_endpoints_XML(void)
 }
 
 /**
- * \breif Set the endpoints for a route from lua
+ * \brief Set the endpoints for a route from lua
  */
 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
 {
@@ -314,12 +314,18 @@ static void parse_E_link_ctn_new_elem(char *link_id)
 
 static void parse_E_link_ctn_new_elem_XML(void)
 {
-  if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
-         parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
-  if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP)
-         parse_E_link_ctn_new_elem(bprintf("%s_UP",A_surfxml_link_ctn_id));
-  if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN)
-         parse_E_link_ctn_new_elem(bprintf("%s_DOWN",A_surfxml_link_ctn_id));
+  if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
+    parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
+  if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
+    char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
+    parse_E_link_ctn_new_elem(link_id);
+    free(link_id);
+  }
+  if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
+    char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
+    parse_E_link_ctn_new_elem(link_id);
+    free(link_id);
+  }
 }
 
 /**
@@ -571,8 +577,8 @@ static xbt_dynar_t elements_father(const char *src, const char *dst)
   }
 
   /* (3) find the common father */
-  index_src = (path_src->used) - 1;
-  index_dst = (path_dst->used) - 1;
+  index_src = path_src->used - 1;
+  index_dst = path_dst->used - 1;
   current_src = xbt_dynar_get_ptr(path_src, index_src);
   current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
   while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
@@ -998,7 +1004,7 @@ static e_surf_network_element_type_t get_network_element_type(const char
  * 
  * Make a global routing structure and set all the parsing functions.
  */
-void routing_model_create(size_t size_of_links, void *loopback, double_f_pvoid_t get_link_latency_fun  )
+void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
 {
 
   /* config the uniq global routing */
@@ -1284,10 +1290,10 @@ static void model_full_set_route(routing_component_t rc, const char *src,
        {
                if(route->dst_gateway && route->src_gateway)
                {
-                       char * gw_src = bprintf("%s",route->src_gateway);
-                       char * gw_dst = bprintf("%s",route->dst_gateway);
-                       route->src_gateway = bprintf("%s",gw_dst);
-                       route->dst_gateway = bprintf("%s",gw_src);
+                  char *gw_src = xbt_strdup(route->src_gateway);
+                  char *gw_dst = xbt_strdup(route->dst_gateway);
+                  route->src_gateway = gw_dst;
+                  route->dst_gateway = gw_src;
                }
                if(TO_ROUTE_FULL(*dst_id, *src_id))
                {
@@ -1682,10 +1688,10 @@ static void model_floyd_set_route(routing_component_t rc, const char *src,
                {
                        if(route->dst_gateway && route->src_gateway)
                        {
-                               char * gw_src = bprintf("%s",route->src_gateway);
-                               char * gw_dst = bprintf("%s",route->dst_gateway);
-                               route->src_gateway = bprintf("%s",gw_dst);
-                               route->dst_gateway = bprintf("%s",gw_src);
+                          char *gw_src = xbt_strdup(route->src_gateway);
+                          char *gw_dst = xbt_strdup(route->dst_gateway);
+                          route->src_gateway = gw_dst;
+                          route->dst_gateway = gw_src;
                        }
 
                        if(!route->dst_gateway && !route->src_gateway)
@@ -2243,9 +2249,9 @@ static void rule_route_free(void *e)
     xbt_dynar_free(&(*elem)->re_str_link);
     pcre_free((*elem)->re_src);
     pcre_free((*elem)->re_dst);
-    xbt_free((*elem));
+    xbt_free(*elem);
   }
-  (*elem) = NULL;
+  *elem = NULL;
 }
 
 static void rule_route_extended_free(void *e)
@@ -2257,7 +2263,7 @@ static void rule_route_extended_free(void *e)
     pcre_free((*elem)->generic_rule_route.re_dst);
     xbt_free((*elem)->re_src_gateway);
     xbt_free((*elem)->re_dst_gateway);
-    xbt_free((*elem));
+    xbt_free(*elem);
   }
 }
 
@@ -2774,16 +2780,14 @@ static void generic_set_autonomous_system(routing_component_t rc,
   xbt_dict_set(_to_index, name, id, xbt_free);
 }
 
-static int surf_pointer_resource_cmp(const void *a, const void *b) {
-       if(a == b)
-               return 0;
-       return 1;
+static int surf_pointer_resource_cmp(const void *a, const void *b)
+{
+  return a != b;
 }
 
-static int surf_link_resource_cmp(const void *a, const void *b) {
-       if( memcmp(a,b,global_routing->size_of_link) == 0 );
-               return 0;
-       return 1;
+static int surf_link_resource_cmp(const void *a, const void *b)
+{
+  return !!memcmp(a,b,global_routing->size_of_link);
 }
 
 static void generic_set_bypassroute(routing_component_t rc,
@@ -2874,8 +2878,8 @@ static route_extended_t generic_get_bypassroute(routing_component_t rc,
   }
 
   /* (3) find the common father */
-  index_src = (path_src->used) - 1;
-  index_dst = (path_dst->used) - 1;
+  index_src = path_src->used - 1;
+  index_dst = path_dst->used - 1;
   current_src = xbt_dynar_get_ptr(path_src, index_src);
   current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
   while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
@@ -2888,8 +2892,8 @@ static route_extended_t generic_get_bypassroute(routing_component_t rc,
     current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
   }
 
-  int max_index_src = (path_src->used) - 1;
-  int max_index_dst = (path_dst->used) - 1;
+  int max_index_src = path_src->used - 1;
+  int max_index_dst = path_dst->used - 1;
 
   int max_index = max(max_index_src, max_index_dst);
   int i, max;
@@ -3273,6 +3277,8 @@ static void routing_parse_Scluster(void)
       SURFXML_START_TAG(link);
       SURFXML_END_TAG(link);
 
+      free(link_id);
+      free(host_id);
       break;
 
     case 2:
@@ -3313,6 +3319,9 @@ static void routing_parse_Scluster(void)
         SURFXML_BUFFER_SET(link_state_file, "");
         SURFXML_START_TAG(link);
         SURFXML_END_TAG(link);
+
+        free(link_id);
+        free(host_id);
       }
       break;
 
@@ -3322,6 +3331,7 @@ static void routing_parse_Scluster(void)
 
     xbt_dynar_free(&radical_ends);
   }
+  xbt_dynar_free(&radical_elements);
 
   DEBUG0(" ");
   router_id =
@@ -3368,15 +3378,23 @@ static void routing_parse_Scluster(void)
   DEBUG0(" ");
 
 #ifdef HAVE_PCRE_LIB
-  char *new_suffix = bprintf("%s", "");
+  char *new_suffix = xbt_strdup("");
 
   radical_elements = xbt_str_split(cluster_suffix, ".");
   xbt_dynar_foreach(radical_elements, iter, groups) {
     if (strcmp(groups, "")) {
-      new_suffix = bprintf("%s\\.%s", new_suffix, groups);
+      char *old_suffix = new_suffix;
+      new_suffix = bprintf("%s\\.%s", old_suffix, groups);
+      free(old_suffix);
     }
   }
   route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
+  xbt_dynar_free(&radical_elements);
+  free(new_suffix);
+
+  char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
+  char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
+  char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
 
   DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
   DEBUG0("symmetrical=\"NO\">");
@@ -3385,22 +3403,22 @@ static void routing_parse_Scluster(void)
   A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
   SURFXML_START_TAG(route);
 
-  DEBUG1("<link_ctn\tid=\"%s_link_$1src\"/>", cluster_id);
-  SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1src", cluster_id));
+  DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_src);
+  SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
   SURFXML_START_TAG(link_ctn);
   SURFXML_END_TAG(link_ctn);
 
-  DEBUG1("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
-  SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
+  DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
+  SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
   SURFXML_START_TAG(link_ctn);
   SURFXML_END_TAG(link_ctn);
 
-  DEBUG1("<link_ctn\tid=\"%s_link_$1dst\"/>", cluster_id);
-  SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1dst", cluster_id));
+  DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
+  SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
@@ -3409,6 +3427,11 @@ static void routing_parse_Scluster(void)
 
   DEBUG0("</route>");
   SURFXML_END_TAG(route);
+
+  free(pcre_link_dst);
+  free(pcre_link_backbone);
+  free(pcre_link_src);
+  free(route_src_dst);
 #else
   for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
     for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
@@ -3480,8 +3503,13 @@ static void routing_parse_Scluster(void)
     }
   }
   xbt_dynar_free(&tab_elements_num);
+  free(router_id);
+
 #endif
 
+  free(link_backbone);
+  free(link_router);
+
   DEBUG0("</AS>");
   SURFXML_END_TAG(AS);
   DEBUG0(" ");