Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sanitize the memory handling of config elems description
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Jun 2009 20:22:13 +0000 (20:22 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Jun 2009 20:22:13 +0000 (20:22 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6372 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/surf/surf_config.c
src/xbt/config.c

index dbaf64d..3e76e71 100644 (file)
@@ -121,9 +121,9 @@ void surf_config_init(int *argc, char **argv) {
                while (*(++p) != '\0');
                for (i=0;surf_workstation_model_description[i].name;i++)
                        p+=sprintf(p,"%s%s",(i==0?"":", "),surf_workstation_model_description[i].name);
                while (*(++p) != '\0');
                for (i=0;surf_workstation_model_description[i].name;i++)
                        p+=sprintf(p,"%s%s",(i==0?"":", "),surf_workstation_model_description[i].name);
-               default_value = (char*)"CLM03";
+               default_value = xbt_strdup("CLM03");
                xbt_cfg_register(&_surf_cfg_set,
                xbt_cfg_register(&_surf_cfg_set,
-                               "workstation_model", xbt_strdup(description),  xbt_cfgelm_string, &default_value, 1, 1,
+                               "workstation_model", description,  xbt_cfgelm_string, &default_value, 1, 1,
                                &_surf_cfg_cb__workstation_model, NULL);
 
                sprintf(description,"The model to use for the CPU. Possible values: ");
                                &_surf_cfg_cb__workstation_model, NULL);
 
                sprintf(description,"The model to use for the CPU. Possible values: ");
@@ -131,9 +131,9 @@ void surf_config_init(int *argc, char **argv) {
                while (*(++p) != '\0');
                for (i=0;surf_cpu_model_description[i].name;i++)
                        p+=sprintf(p,"%s%s",(i==0?"":", "),surf_cpu_model_description[i].name);
                while (*(++p) != '\0');
                for (i=0;surf_cpu_model_description[i].name;i++)
                        p+=sprintf(p,"%s%s",(i==0?"":", "),surf_cpu_model_description[i].name);
-               default_value = (char*)"Cas01";
+               default_value = xbt_strdup("Cas01");
                xbt_cfg_register(&_surf_cfg_set,
                xbt_cfg_register(&_surf_cfg_set,
-                               "cpu_model", xbt_strdup(description), xbt_cfgelm_string, &default_value, 1, 1,
+                               "cpu_model", description, xbt_cfgelm_string, &default_value, 1, 1,
                                &_surf_cfg_cb__cpu_model, NULL);
 
                sprintf(description,"The model to use for the network. Possible values: ");
                                &_surf_cfg_cb__cpu_model, NULL);
 
                sprintf(description,"The model to use for the network. Possible values: ");
@@ -141,10 +141,11 @@ void surf_config_init(int *argc, char **argv) {
                while (*(++p) != '\0');
                for (i=0;surf_network_model_description[i].name;i++)
                        p+=sprintf(p,"%s%s",(i==0?"":", "),surf_network_model_description[i].name);
                while (*(++p) != '\0');
                for (i=0;surf_network_model_description[i].name;i++)
                        p+=sprintf(p,"%s%s",(i==0?"":", "),surf_network_model_description[i].name);
-               default_value = (char*)"CM02";
+               default_value = xbt_strdup("CM02");
                xbt_cfg_register(&_surf_cfg_set,
                                "network_model", description, xbt_cfgelm_string, &default_value, 1, 1,
                                &_surf_cfg_cb__network_model, NULL);
                xbt_cfg_register(&_surf_cfg_set,
                                "network_model", description, xbt_cfgelm_string, &default_value, 1, 1,
                                &_surf_cfg_cb__network_model, NULL);
+               xbt_free(description);
 
                double default_TCP_GAMMA = 20000.0;
                xbt_cfg_register(&_surf_cfg_set,"TCP_gamma","Size of the biggest TCP window",
 
                double default_TCP_GAMMA = 20000.0;
                xbt_cfg_register(&_surf_cfg_set,"TCP_gamma","Size of the biggest TCP window",
index 7d663cb..20875fa 100644 (file)
@@ -29,7 +29,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support");
 
 typedef struct {
   /* Description */
 
 typedef struct {
   /* Description */
-  const char *desc;
+  char *desc;
 
   /* Allowed type of the variable */
   e_xbt_cfgelm_type_t type;
 
   /* Allowed type of the variable */
   e_xbt_cfgelm_type_t type;
@@ -184,6 +184,7 @@ void xbt_cfgelm_free(void *data)
   DEBUG1("Frees cfgelm %p", c);
   if (!c)
     return;
   DEBUG1("Frees cfgelm %p", c);
   if (!c)
     return;
+  xbt_free(c->desc);
   xbt_dynar_free(&(c->content));
   free(c);
 }
   xbt_dynar_free(&(c->content));
   free(c);
 }
@@ -221,7 +222,7 @@ xbt_cfg_register(xbt_cfg_t *cfg,
   DEBUG8("Register cfg elm %s (%s) (%d to %d %s (=%d) @%p in set %p)",
          name, desc, min, max, xbt_cfgelm_type_name[type], type, res, *cfg);
 
   DEBUG8("Register cfg elm %s (%s) (%d to %d %s (=%d) @%p in set %p)",
          name, desc, min, max, xbt_cfgelm_type_name[type], type, res, *cfg);
 
-  res->desc = desc;
+  res->desc = xbt_strdup(desc);
   res->type = type;
   res->min = min;
   res->max = max;
   res->type = type;
   res->min = min;
   res->max = max;