Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Plug a memleak.
[simgrid.git] / src / surf / surfxml_parse.c
index d8874a58fa964e6cbeef1c15c0700a6b8329fc2d..12d4c49c64c0df9146c41513f836edfb3017c66d 100644 (file)
@@ -31,7 +31,7 @@ xbt_dict_t trace_connect_list_latency = NULL;
 /* This buffer is used to store the original buffer before substituing it by out own buffer. Usefull for the foreach tag */
 char* old_buff;
 /* Stores the set name reffered to by the foreach tag */
-static const char* foreach_set_name;
+static char* foreach_set_name;
 static xbt_dynar_t main_STag_surfxml_host_cb_list = NULL;
 static xbt_dynar_t main_ETag_surfxml_host_cb_list = NULL;
 static xbt_dynar_t main_STag_surfxml_link_cb_list = NULL;
@@ -228,8 +228,6 @@ void STag_surfxml_platform(void)
              "is available in the contrib/platform_generation directory "
              "of the simgrid repository.");
 
-  if (set_list == NULL) set_list = xbt_dict_new(); 
-
   surfxml_call_cb_functions(STag_surfxml_platform_cb_list);
 
 }
@@ -506,7 +504,7 @@ static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
 }
 
 static void parse_route_set_endpoints(void) {
-  route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
+  route_link_list = xbt_dynar_new(sizeof(char *), NULL);
 }
 
 static void init_data(void)
@@ -518,7 +516,8 @@ static void init_data(void)
   route_multi_table = xbt_dict_new();
   route_multi_elements = xbt_dynar_new(sizeof(char*), NULL);
   traces_set_list = xbt_dict_new();
-   
+  if (set_list == NULL) set_list = xbt_dict_new();
+
   trace_connect_list_host_avail = xbt_dict_new();
   trace_connect_list_power = xbt_dict_new();
   trace_connect_list_link_avail = xbt_dict_new();
@@ -548,11 +547,25 @@ static void free_data(void)
 
   xbt_dict_foreach(route_table, cursor, key, data) {
     xbt_dynar_t links = (xbt_dynar_t)data;
+    char *name;
+    unsigned int cpt = 0;
+
+    xbt_dynar_foreach (links, cpt, name)  free(name);
     xbt_dynar_free(&links);
   }
   xbt_dict_free(&route_table);
   route_link_list = NULL;
 
+  xbt_dict_foreach(set_list, cursor, key, data) {
+    xbt_dynar_t set = (xbt_dynar_t)data;
+    char *name;
+    unsigned int cpt = 0;
+
+    xbt_dynar_foreach (set, cpt, name)  free(name);
+    xbt_dynar_free(&set);
+  }
+  xbt_dict_free(&set_list);
+
   xbt_dict_free(&trace_connect_list_host_avail);
   xbt_dict_free(&trace_connect_list_power);
   xbt_dict_free(&trace_connect_list_link_avail);
@@ -651,6 +664,11 @@ static void parse_sets(void)
   } 
   
   xbt_dict_set(set_list, id, current_set, NULL);
+
+  free(radical);
+  free(suffix);
+  free(prefix);
+  free(id);
 }
 
 static const char* surfxml_host_power;
@@ -751,6 +769,8 @@ static void finalize_link_foreach(void)
   current_property_set = xbt_dict_new();
 
   surfxml_bufferstack = old_buff;
+  free(foreach_set_name);
+  foreach_set_name=NULL;
 }
 
 static void parse_foreach(void)
@@ -832,6 +852,7 @@ void manage_route(xbt_dict_t routing_table, const char *route_name, int action,
                                    xbt_dynar_foreach(links, cpt, value) {      
                                        xbt_dynar_push(route_link_list,&value);
                                    }
+                                   xbt_dynar_free(&links);
                                     break;
         case A_surfxml_route_action_POSTPEND: /* add existing links in front; links + route_link_list */ 
                                    xbt_dynar_foreach(route_link_list, cpt, value) {
@@ -841,6 +862,7 @@ void manage_route(xbt_dict_t routing_table, const char *route_name, int action,
                                     route_link_list = links;
                                    break;
         case A_surfxml_route_action_OVERRIDE:
+                                   xbt_dynar_free(&links);
                                     break;
         default:break;
      }