From e03467b79d75151432c781357be39a5b6a282b76 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 9 Mar 2020 09:59:52 +0100 Subject: [PATCH] plug leak and use string --- .../s4u/host-on-off-actors/host-on-off-actors.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/teshsuite/s4u/host-on-off-actors/host-on-off-actors.cpp b/teshsuite/s4u/host-on-off-actors/host-on-off-actors.cpp index a651ff4608..246ceec391 100644 --- a/teshsuite/s4u/host-on-off-actors/host-on-off-actors.cpp +++ b/teshsuite/s4u/host-on-off-actors/host-on-off-actors.cpp @@ -25,30 +25,33 @@ static void actor_daemon() static void commTX() { XBT_INFO(" Start TX"); - simgrid::s4u::Mailbox::by_name("comm")->put_init(xbt_strdup("COMM"), 100000000)->detach(); + std::string* payload = new std::string("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"); } static void commRX() { - char* payload = nullptr; + const std::string* payload = nullptr; XBT_INFO(" Start RX"); try { - payload = static_cast(simgrid::s4u::Mailbox::by_name("comm")->get()); - XBT_INFO(" Receive message: %s", payload); + payload = static_cast(simgrid::s4u::Mailbox::by_name("comm")->get()); + XBT_INFO(" Receive message: %s", payload->c_str()); } catch (const simgrid::HostFailureException&) { XBT_INFO(" Receive message: HOST_FAILURE"); } catch (const simgrid::NetworkFailureException&) { XBT_INFO(" Receive message: TRANSFER_FAILURE"); } - xbt_free(payload); + delete payload; XBT_INFO(" RX Done"); } -- 2.20.1