Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
plug leaks
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 8 Aug 2017 07:11:12 +0000 (09:11 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 8 Aug 2017 07:41:51 +0000 (09:41 +0200)
examples/msg/platform-properties/platform-properties.c
examples/simdag/properties/sd_properties.c
src/surf/sg_platf.cpp

index a7b4d59..5158498 100644 (file)
@@ -33,7 +33,7 @@ static void test_host(const char*hostname)
   XBT_INFO("   Property: %s old value: %s", exist, value);
 
   XBT_INFO("== Trying to modify a host property");
   XBT_INFO("   Property: %s old value: %s", exist, value);
 
   XBT_INFO("== Trying to modify a host property");
-  MSG_host_set_property_value(thehost, exist, xbt_strdup("250"));
+  MSG_host_set_property_value(thehost, exist, (char*)"250");
 
   /* Test if we have changed the value */
   value = MSG_host_get_property_value(thehost, exist);
 
   /* Test if we have changed the value */
   value = MSG_host_get_property_value(thehost, exist);
@@ -42,7 +42,9 @@ static void test_host(const char*hostname)
   XBT_INFO("   Property: %s old value: %s", exist, value);
 
   /* Restore the value for the next test */
   XBT_INFO("   Property: %s old value: %s", exist, value);
 
   /* Restore the value for the next test */
-  MSG_host_set_property_value(thehost, exist, xbt_strdup("180"));
+  MSG_host_set_property_value(thehost, exist, (char*)"180");
+
+  xbt_dict_free(&props);
 }
 
 static int alice(int argc, char *argv[]) { /* Dump what we have on the current host */
 }
 
 static int alice(int argc, char *argv[]) { /* Dump what we have on the current host */
@@ -87,6 +89,7 @@ static int bob(int argc, char *argv[])
 
   value = MSG_process_get_property_value(MSG_process_self(), noexist);
   xbt_assert(!value, "The property is defined (it shouldnt)");
 
   value = MSG_process_get_property_value(MSG_process_self(), noexist);
   xbt_assert(!value, "The property is defined (it shouldnt)");
+  xbt_dict_free(&props);
 
   return 0;
 }
 
   return 0;
 }
index 2e437de..7e8d159 100644 (file)
@@ -38,22 +38,24 @@ int main(int argc, char **argv)
 
 
   /* Print the properties of 'host1' */
 
 
   /* Print the properties of 'host1' */
-  xbt_dict_foreach(props, cursor, key, data) {
+  xbt_dict_foreach (props, cursor, key, data)
     XBT_INFO("\tProperty: %s has value: %s", key, data);
     XBT_INFO("\tProperty: %s has value: %s", key, data);
-  }
 
   /* Try to get a property that does not exist */
   value = sg_host_get_property_value(h1, noexist);
   XBT_INFO("\tProperty: %s has value: %s", noexist, value?value:"Undefined (NULL)");
 
 
   /* Try to get a property that does not exist */
   value = sg_host_get_property_value(h1, noexist);
   XBT_INFO("\tProperty: %s has value: %s", noexist, value?value:"Undefined (NULL)");
 
+  xbt_dict_free(&props);
+
   /* Get the property list of 'host2' */
   XBT_INFO("Property list for host %s", name2);
   props = sg_host_get_properties(h2);
 
   /* Print the properties of 'host2' */
   /* Get the property list of 'host2' */
   XBT_INFO("Property list for host %s", name2);
   props = sg_host_get_properties(h2);
 
   /* Print the properties of 'host2' */
-  xbt_dict_foreach(props, cursor, key, data) {
+  xbt_dict_foreach (props, cursor, key, data)
     XBT_INFO("\tProperty: %s on host: %s", key, data);
     XBT_INFO("\tProperty: %s on host: %s", key, data);
-  }
+
+  xbt_dict_free(&props);
 
   /* Modify an existing property test. First check it exists */
   XBT_INFO("Modify an existing property");
 
   /* Modify an existing property test. First check it exists */
   XBT_INFO("Modify an existing property");
index 016f201..ad15673 100644 (file)
@@ -427,6 +427,12 @@ void sg_platf_new_bypassRoute(sg_platf_route_cbarg_t bypassRoute)
 
 void sg_platf_new_process(sg_platf_process_cbarg_t process)
 {
 
 void sg_platf_new_process(sg_platf_process_cbarg_t process)
 {
+  std::map<std::string, std::string> props;
+  if (process->properties) {
+    for (auto elm : *process->properties)
+      props.insert({elm.first, elm.second});
+    delete process->properties;
+  }
   sg_host_t host = sg_host_by_name(process->host);
   if (not host) {
     // The requested host does not exist. Do a nice message to the user
   sg_host_t host = sg_host_by_name(process->host);
   if (not host) {
     // The requested host does not exist. Do a nice message to the user
@@ -462,7 +468,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
   arg->data = nullptr;
   arg->host = host;
   arg->kill_time = kill_time;
   arg->data = nullptr;
   arg->host = host;
   arg->kill_time = kill_time;
-  arg->properties = current_property_set;
+  arg->properties = &props;
 
   host->extension<simgrid::simix::Host>()->boot_processes.push_back(arg);
 
 
   host->extension<simgrid::simix::Host>()->boot_processes.push_back(arg);
 
@@ -474,7 +480,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
     arg->data = nullptr;
     arg->host = host;
     arg->kill_time = kill_time;
     arg->data = nullptr;
     arg->host = host;
     arg->kill_time = kill_time;
-    arg->properties = current_property_set;
+    arg->properties = &props;
 
     XBT_DEBUG("Process %s@%s will be started at time %f", arg->name.c_str(), arg->host->getCname(), start_time);
     SIMIX_timer_set(start_time, [arg, auto_restart]() {
 
     XBT_DEBUG("Process %s@%s will be started at time %f", arg->name.c_str(), arg->host->getCname(), start_time);
     SIMIX_timer_set(start_time, [arg, auto_restart]() {
@@ -490,7 +496,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
     XBT_DEBUG("Starting Process %s(%s) right now", arg->name.c_str(), host->getCname());
 
     smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), std::move(code), nullptr, host,
     XBT_DEBUG("Starting Process %s(%s) right now", arg->name.c_str(), host->getCname());
 
     smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), std::move(code), nullptr, host,
-                                                              current_property_set, nullptr);
+                                                              arg->properties, nullptr);
 
     /* The actor creation will fail if the host is currently dead, but that's fine */
     if (actor != nullptr) {
 
     /* The actor creation will fail if the host is currently dead, but that's fine */
     if (actor != nullptr) {