From 8cd2b8b1e341896e2b8c3e96eb3778316855504c Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 13 Sep 2017 00:16:56 +0200 Subject: [PATCH] fewer explicit news are fewer possible leaks --- examples/s4u/actions-comm/s4u-actions-comm.cpp | 17 ++++++++--------- .../s4u/actions-storage/s4u-actions-storage.cpp | 15 +++++++-------- examples/s4u/actor-create/s4u-actor-create.cpp | 16 +++++++--------- examples/s4u/actor-daemon/s4u-actor-daemon.cpp | 8 +++----- examples/s4u/actor-kill/s4u-actor-kill.cpp | 9 ++++----- .../s4u/actor-migration/s4u-actor-migration.cpp | 9 ++++----- .../s4u/actor-suspend/s4u-actor-suspend.cpp | 9 ++++----- examples/s4u/app-bittorrent/s4u-bittorrent.cpp | 13 ++++++------- .../app-masterworker/s4u-app-masterworker.cpp | 15 +++++++-------- examples/s4u/app-pingpong/s4u-app-pingpong.cpp | 9 ++++----- .../s4u/app-token-ring/s4u-app-token-ring.cpp | 13 ++++++------- examples/s4u/dht-chord/s4u-dht-chord.cpp | 13 ++++++------- examples/s4u/io/s4u-io.cpp | 8 ++++---- examples/s4u/mutex/s4u-mutex.cpp | 7 +++---- .../s4u/plugin-hostload/s4u-plugin-hostload.cpp | 10 ++++------ 15 files changed, 77 insertions(+), 94 deletions(-) diff --git a/examples/s4u/actions-comm/s4u-actions-comm.cpp b/examples/s4u/actions-comm/s4u-actions-comm.cpp index 2779185680..f620071304 100644 --- a/examples/s4u/actions-comm/s4u-actions-comm.cpp +++ b/examples/s4u/actions-comm/s4u-actions-comm.cpp @@ -85,7 +85,7 @@ public: int main(int argc, char *argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 2, "Usage: %s platform_file deployment_file [action_files]\n" "\t# if all actions are in the same file\n" @@ -94,11 +94,11 @@ int main(int argc, char *argv[]) "\tExample: %s msg_platform.xml msg_deployment.xml ", argv[0], argv[0], argv[0]); - e->loadPlatform(argv[1]); - e->registerDefault(&simgrid::xbt::replay_runner); - e->registerFunction("p0"); - e->registerFunction("p1"); - e->loadDeployment(argv[2]); + e.loadPlatform(argv[1]); + e.registerDefault(&simgrid::xbt::replay_runner); + e.registerFunction("p0"); + e.registerFunction("p1"); + e.loadDeployment(argv[2]); /* Action registration */ xbt_replay_action_register("compute", Replayer::compute); @@ -109,15 +109,14 @@ int main(int argc, char *argv[]) simgrid::xbt::action_fs = new std::ifstream(argv[3], std::ifstream::in); } - e->run(); + e.run(); if (argv[3]) { delete simgrid::xbt::action_fs; simgrid::xbt::action_fs = nullptr; } - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/actions-storage/s4u-actions-storage.cpp b/examples/s4u/actions-storage/s4u-actions-storage.cpp index 85ffb9d975..79a8ababd3 100644 --- a/examples/s4u/actions-storage/s4u-actions-storage.cpp +++ b/examples/s4u/actions-storage/s4u-actions-storage.cpp @@ -102,7 +102,7 @@ public: int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 3, "Usage: %s platform_file deployment_file [action_files]\n" "\texample: %s platform.xml deployment.xml actions # if all actions are in the same file\n" @@ -110,10 +110,10 @@ int main(int argc, char* argv[]) "\texample: %s platform.xml deployment.xml", argv[0], argv[0], argv[0]); - e->loadPlatform(argv[1]); - e->registerDefault(&simgrid::xbt::replay_runner); - e->registerFunction("p0"); - e->loadDeployment(argv[2]); + e.loadPlatform(argv[1]); + e.registerDefault(&simgrid::xbt::replay_runner); + e.registerFunction("p0"); + e.loadDeployment(argv[2]); /* Action registration */ xbt_replay_action_register("open", Replayer::open); @@ -124,15 +124,14 @@ int main(int argc, char* argv[]) simgrid::xbt::action_fs = new std::ifstream(argv[3], std::ifstream::in); } - e->run(); + e.run(); if (argv[3]) { delete simgrid::xbt::action_fs; simgrid::xbt::action_fs = nullptr; } - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/actor-create/s4u-actor-create.cpp b/examples/s4u/actor-create/s4u-actor-create.cpp index ca6cd9b171..33ed245dac 100644 --- a/examples/s4u/actor-create/s4u-actor-create.cpp +++ b/examples/s4u/actor-create/s4u-actor-create.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2016. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -87,10 +87,10 @@ public: int main(int argc, char** argv) { /* When your program starts, you have to first start a new simulation engine, as follows */ - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); /* Then you should load a platform file, describing your simulated platform */ - e->loadPlatform("../../platforms/small_platform.xml"); + e.loadPlatform("../../platforms/small_platform.xml"); /* And now you have to ask SimGrid to actually start your actors. * @@ -100,21 +100,19 @@ int main(int argc, char** argv) simgrid::s4u::Actor::createActor("sender1", simgrid::s4u::Host::by_name("Tremblay"), Sender()); /* The second way is to first register your function, and then retrieve it */ - e->registerFunction("sender"); // The sender is passed as a template parameter here + e.registerFunction("sender"); // The sender is passed as a template parameter here std::vector args; // Here we declare the parameter that the actor will get args.push_back("GloubiBoulga"); // Add a parameter to the set (we could have done it in the first approach too) simgrid::s4u::Actor::createActor("sender2", simgrid::s4u::Host::by_name("Jupiter"), "sender", args); /* The third way to start your actors is to use a deployment file. */ - e->registerFunction("receiver"); // You first have to register the actor as with the second approach - e->loadDeployment("s4u-actor-create_d.xml"); // And then, you load the deployment file + e.registerFunction("receiver"); // You first have to register the actor as with the second approach + e.loadDeployment("s4u-actor-create_d.xml"); // And then, you load the deployment file /* Once every actors are started in the engine, the simulation can start */ - e->run(); + e.run(); /* Once the simulation is done, the program is ended */ - delete e; - return 0; } diff --git a/examples/s4u/actor-daemon/s4u-actor-daemon.cpp b/examples/s4u/actor-daemon/s4u-actor-daemon.cpp index b415f288b4..4c8d19ca20 100644 --- a/examples/s4u/actor-daemon/s4u-actor-daemon.cpp +++ b/examples/s4u/actor-daemon/s4u-actor-daemon.cpp @@ -31,14 +31,12 @@ static void my_daemon() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Boivin"), worker); simgrid::s4u::Actor::createActor("daemon", simgrid::s4u::Host::by_name("Tremblay"), my_daemon); - e->run(); - - delete e; + e.run(); return 0; } diff --git a/examples/s4u/actor-kill/s4u-actor-kill.cpp b/examples/s4u/actor-kill/s4u-actor-kill.cpp index e6a77aaf7f..81ce0a2471 100644 --- a/examples/s4u/actor-kill/s4u-actor-kill.cpp +++ b/examples/s4u/actor-kill/s4u-actor-kill.cpp @@ -38,17 +38,16 @@ static void killer() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); /* - Load the platform description */ + e.loadPlatform(argv[1]); /* - Load the platform description */ /* - Create and deploy killer process, that will create the victim process */ simgrid::s4u::Actor::createActor("killer", simgrid::s4u::Host::by_name("Tremblay"), killer); - e->run(); /* - Run the simulation */ + e.run(); /* - Run the simulation */ - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/actor-migration/s4u-actor-migration.cpp b/examples/s4u/actor-migration/s4u-actor-migration.cpp index 102843c2cd..5db7924478 100644 --- a/examples/s4u/actor-migration/s4u-actor-migration.cpp +++ b/examples/s4u/actor-migration/s4u-actor-migration.cpp @@ -58,9 +58,9 @@ static void policeman() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); /* - Load the platform description */ + e.loadPlatform(argv[1]); /* - Load the platform description */ /* - Create and deploy the emigrant and policeman processes */ simgrid::s4u::Actor::createActor("emigrant", simgrid::s4u::Host::by_name("Jacquelin"), emigrant); @@ -68,10 +68,9 @@ int main(int argc, char* argv[]) checkpoint = simgrid::s4u::Mutex::createMutex(); /* - Initiate the mutex and conditions */ identification = simgrid::s4u::ConditionVariable::createConditionVariable(); - e->run(); + e.run(); - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/actor-suspend/s4u-actor-suspend.cpp b/examples/s4u/actor-suspend/s4u-actor-suspend.cpp index 9d98a4a83b..b663e8e026 100644 --- a/examples/s4u/actor-suspend/s4u-actor-suspend.cpp +++ b/examples/s4u/actor-suspend/s4u-actor-suspend.cpp @@ -66,16 +66,15 @@ static void dream_master() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); /* - Load the platform description */ + e.loadPlatform(argv[1]); /* - Load the platform description */ std::vector list; - e->getHostList(&list); + e.getHostList(&list); simgrid::s4u::Actor::createActor("dream_master", list.front(), dream_master); - e->run(); /* - Run the simulation */ + e.run(); /* - Run the simulation */ - delete e; return 0; } diff --git a/examples/s4u/app-bittorrent/s4u-bittorrent.cpp b/examples/s4u/app-bittorrent/s4u-bittorrent.cpp index d205165aa6..38709b0be3 100644 --- a/examples/s4u/app-bittorrent/s4u-bittorrent.cpp +++ b/examples/s4u/app-bittorrent/s4u-bittorrent.cpp @@ -12,12 +12,12 @@ simgrid::xbt::Extension HostBittorrent::EXTE int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); /* Check the arguments */ xbt_assert(argc > 2, "Usage: %s platform_file deployment_file", argv[0]); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); HostBittorrent::EXTENSION_ID = simgrid::s4u::Host::extension_create(); @@ -26,12 +26,11 @@ int main(int argc, char* argv[]) for (auto const& host : list) host->extension_set(new HostBittorrent(host)); - e->registerFunction("tracker"); - e->registerFunction("peer"); - e->loadDeployment(argv[2]); + e.registerFunction("tracker"); + e.registerFunction("peer"); + e.loadDeployment(argv[2]); - e->run(); + e.run(); - delete e; return 0; } diff --git a/examples/s4u/app-masterworker/s4u-app-masterworker.cpp b/examples/s4u/app-masterworker/s4u-app-masterworker.cpp index c0ce006b50..d360480ac7 100644 --- a/examples/s4u/app-masterworker/s4u-app-masterworker.cpp +++ b/examples/s4u/app-masterworker/s4u-app-masterworker.cpp @@ -85,20 +85,19 @@ public: int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); /** - Load the platform description */ - e->registerFunction("master"); - e->registerFunction("worker"); /** - Register the function to be executed by the processes */ - e->loadDeployment(argv[2]); /** - Deploy the application */ + e.loadPlatform(argv[1]); /** - Load the platform description */ + e.registerFunction("master"); + e.registerFunction("worker"); /** - Register the function to be executed by the processes */ + e.loadDeployment(argv[2]); /** - Deploy the application */ - e->run(); /** - Run the simulation */ + e.run(); /** - Run the simulation */ - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/app-pingpong/s4u-app-pingpong.cpp b/examples/s4u/app-pingpong/s4u-app-pingpong.cpp index d47ff48d45..a644f694fd 100644 --- a/examples/s4u/app-pingpong/s4u-app-pingpong.cpp +++ b/examples/s4u/app-pingpong/s4u-app-pingpong.cpp @@ -54,9 +54,9 @@ static void ponger(std::vector args) int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); std::vector args; args.push_back("Jupiter"); simgrid::s4u::Actor::createActor("pinger", simgrid::s4u::Host::by_name("Tremblay"), pinger, args); @@ -66,10 +66,9 @@ int main(int argc, char* argv[]) simgrid::s4u::Actor::createActor("ponger", simgrid::s4u::Host::by_name("Jupiter"), ponger, args); - e->run(); + e.run(); - XBT_INFO("Total simulation time: %.3f", e->getClock()); - delete e; + XBT_INFO("Total simulation time: %.3f", e.getClock()); return 0; } diff --git a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp index a5c3d7fa4a..ce84f9c540 100644 --- a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp +++ b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp @@ -55,22 +55,21 @@ public: int main(int argc, char** argv) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); - XBT_INFO("Number of hosts '%zu'", e->getHostCount()); + XBT_INFO("Number of hosts '%zu'", e.getHostCount()); int id = 0; std::vector list; - e->getHostList(&list); + e.getHostList(&list); for (auto const& host : list) { /* - Give a unique rank to each host and create a @ref relay_runner process on each */ simgrid::s4u::Actor::createActor((std::to_string(id)).c_str(), host, RelayRunner()); id++; } - e->run(); - XBT_INFO("Simulation time %g", e->getClock()); + e.run(); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/dht-chord/s4u-dht-chord.cpp b/examples/s4u/dht-chord/s4u-dht-chord.cpp index 96bae87f1f..5c819f1f7b 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.cpp +++ b/examples/s4u/dht-chord/s4u-dht-chord.cpp @@ -41,7 +41,7 @@ static void chord_exit() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 2, "Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n" "\tExample: %s ../msg_platform.xml chord.xml\n", argv[0], argv[0]); @@ -63,19 +63,18 @@ int main(int argc, char* argv[]) options++; } - e->loadPlatform(options[0]); + e.loadPlatform(options[0]); chord_init(); - e->registerFunction("node"); - e->loadDeployment(options[1]); + e.registerFunction("node"); + e.loadDeployment(options[1]); - e->run(); + e.run(); - XBT_INFO("Simulated time: %g", e->getClock()); + XBT_INFO("Simulated time: %g", e.getClock()); chord_exit(); - delete e; return 0; } diff --git a/examples/s4u/io/s4u-io.cpp b/examples/s4u/io/s4u-io.cpp index 789bf1cdb0..fb4bc28113 100644 --- a/examples/s4u/io/s4u-io.cpp +++ b/examples/s4u/io/s4u-io.cpp @@ -83,10 +83,10 @@ public: int main(int argc, char **argv) { - simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv); - e->loadPlatform("../../platforms/storage/storage.xml"); + simgrid::s4u::Engine e(&argc, argv); + e.loadPlatform("../../platforms/storage/storage.xml"); simgrid::s4u::Actor::createActor("host", simgrid::s4u::Host::by_name("denise"), MyHost()); - e->run(); - delete e; + e.run(); + return 0; } diff --git a/examples/s4u/mutex/s4u-mutex.cpp b/examples/s4u/mutex/s4u-mutex.cpp index 2f2afd9ccd..b1e352334f 100644 --- a/examples/s4u/mutex/s4u-mutex.cpp +++ b/examples/s4u/mutex/s4u-mutex.cpp @@ -60,11 +60,10 @@ static void master() int main(int argc, char **argv) { - simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv); - e->loadPlatform("../../platforms/two_hosts.xml"); + simgrid::s4u::Engine e(&argc, argv); + e.loadPlatform("../../platforms/two_hosts.xml"); simgrid::s4u::Actor::createActor("main", simgrid::s4u::Host::by_name("Tremblay"), master); - e->run(); + e.run(); - delete e; return 0; } diff --git a/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp b/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp index 3f6efc4de8..5ddec37fdd 100644 --- a/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp +++ b/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2007-2010, 2013-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -69,17 +68,16 @@ static void execute_load_test() int main(int argc, char* argv[]) { sg_host_load_plugin_init(); - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); simgrid::s4u::Actor::createActor("load_test", simgrid::s4u::Host::by_name("MyHost1"), execute_load_test); - e->run(); + e.run(); XBT_INFO("Total simulation time: %.2f", simgrid::s4u::Engine::getClock()); - delete e; return 0; } -- 2.20.1