Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix mem leak on unhandled exception (e.g. ForceFulKill).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 28 Feb 2022 16:05:54 +0000 (17:05 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 28 Feb 2022 16:05:54 +0000 (17:05 +0100)
teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp

index 50c1f4c..9a89318 100644 (file)
@@ -49,15 +49,14 @@ XBT_ATTRIB_NORETURN static void master()
     xbt_assert(sg4::Engine::get_clock() < cfg_deadline,
                "Failed to run all tasks in less than %d seconds. Is this an infinite loop?", (int)cfg_deadline);
 
-    auto* payload = new double(comp_size);
+    auto payload = std::make_unique<double>(comp_size);
     try {
       XBT_INFO("Try to send a message");
-      mailbox->put(payload, comm_size, 10.0);
+      mailbox->put(payload.get(), comm_size, 10.0);
+      payload.release();
     } catch (const simgrid::TimeoutException&) {
-      delete payload;
       XBT_INFO("Timeouted while sending a task");
     } catch (const simgrid::NetworkFailureException&) {
-      delete payload;
       XBT_INFO("Got a NetworkFailureException. Wait a second before starting again.");
       sg4::this_actor::sleep_for(1);
     }