From: Frederic Suter Date: Tue, 8 Aug 2017 07:11:12 +0000 (+0200) Subject: plug leaks X-Git-Tag: v3_17~230 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1ec34be9aff33d4bb36758eb7a057b30c9d5539c plug leaks --- diff --git a/examples/msg/platform-properties/platform-properties.c b/examples/msg/platform-properties/platform-properties.c index a7b4d5963e..515849849a 100644 --- a/examples/msg/platform-properties/platform-properties.c +++ b/examples/msg/platform-properties/platform-properties.c @@ -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"); - 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); @@ -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 */ - 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 */ @@ -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)"); + xbt_dict_free(&props); return 0; } diff --git a/examples/simdag/properties/sd_properties.c b/examples/simdag/properties/sd_properties.c index 2e437de074..7e8d15926e 100644 --- a/examples/simdag/properties/sd_properties.c +++ b/examples/simdag/properties/sd_properties.c @@ -38,22 +38,24 @@ int main(int argc, char **argv) /* 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); - } /* 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' */ - xbt_dict_foreach(props, cursor, key, data) { + xbt_dict_foreach (props, cursor, 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"); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 016f201ba2..ad15673dde 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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) { + std::map 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 @@ -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->properties = current_property_set; + arg->properties = &props; host->extension()->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->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]() { @@ -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, - 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) {