Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use payload with static storage duration to avoid memory leak.
[simgrid.git] / teshsuite / s4u / host-on-off-actors / host-on-off-actors.cpp
index 62516db7247863ea1aa58e09a2ff606fa2ce0d5c..f394ea42d912928bf7c6d4126a67a2b6d096d28f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2022. 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. */
@@ -25,15 +25,14 @@ XBT_ATTRIB_NORETURN static void actor_daemon()
 static void commTX()
 {
   XBT_INFO("  Start TX");
-  auto* payload = new std::string("COMM");
-  simgrid::s4u::Mailbox::by_name("comm")->put_init(payload, 100000000)->detach();
+  static std::string payload = "COMM";
+  simgrid::s4u::Mailbox::by_name("comm")->put_init(&payload, 100000000)->detach();
   // We should wait a bit (if not the process will end before the communication, hence an exception on the other side).
   try {
     simgrid::s4u::this_actor::sleep_for(30);
   } catch (const simgrid::HostFailureException&) {
     XBT_INFO("The host has died ... as expected.");
   }
-  delete payload;
 
   XBT_INFO("  TX done");
 }
@@ -42,7 +41,7 @@ static void commRX()
 {
   XBT_INFO("  Start RX");
   try {
-    auto payload = simgrid::s4u::Mailbox::by_name("comm")->get_unique<std::string>();
+    auto payload = simgrid::s4u::Mailbox::by_name("comm")->get<std::string>();
     XBT_INFO("  Receive message: %s", payload->c_str());
   } catch (const simgrid::HostFailureException&) {
     XBT_INFO("  Receive message: HOST_FAILURE");
@@ -124,7 +123,7 @@ static void test_launcher(int test_number)
       XBT_INFO("Test 6: Turn on Jupiter, assign a VM on Jupiter, launch an actor inside the VM, and turn off the node");
 
       // Create VM0
-      vm0 = new simgrid::s4u::VirtualMachine("vm0", jupiter, 1);
+      vm0 = jupiter->create_vm("vm0", 1);
       vm0->start();
 
       daemon = simgrid::s4u::Actor::create("actor_daemon", vm0, actor_daemon);