Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't throw exception in destructor (sonar).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 23 Apr 2022 15:12:02 +0000 (17:12 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 23 Apr 2022 15:43:45 +0000 (17:43 +0200)
src/kernel/lmm/System.cpp
src/surf/HostImpl.cpp

index b4e9118..33dc9cf 100644 (file)
@@ -176,9 +176,10 @@ System::System(bool selective_update) : selective_update_active(selective_update
 System::~System()
 {
   while (Variable* var = extract_variable()) {
-    std::string demangled = boost::core::demangle(var->id_ ? typeid(*var->id_).name() : "(unidentified)");
-    XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled.c_str(),
-             var->rank_);
+    const char* name = var->id_ ? typeid(*var->id_).name() : "(unidentified)";
+    boost::core::scoped_demangled_name demangled(name);
+    XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.",
+             demangled.get() ? demangled.get() : name, var->rank_);
     var_free(var);
   }
   while (Constraint* cnst = extract_constraint())
index 488aca5..de2ba8f 100644 (file)
@@ -37,12 +37,17 @@ HostImpl::~HostImpl()
 {
   /* All actors should be gone when the host is turned off (by the end of the simulation). */
   if (not actor_list_.empty()) {
-    std::string msg = "Shutting down host, but it's not empty:";
-    for (auto const& actor : actor_list_)
-      msg += "\n\t" + std::string(actor.get_name());
-
-    EngineImpl::get_instance()->display_all_actor_status();
-    xbt_die("%s", msg.c_str());
+    const char* msg = "Shutting down host, but it's not empty";
+    try {
+      std::string actors;
+      for (auto const& actor : actor_list_)
+        actors += "\n\t" + std::string(actor.get_name());
+
+      EngineImpl::get_instance()->display_all_actor_status();
+      xbt_die("%s:%s", msg, actors.c_str());
+    } catch (std::bad_alloc& ba) {
+      xbt_die("%s (cannot print actor list: %s)", msg, ba.what());
+    }
   }
   for (auto const& arg : actors_at_boot_)
     delete arg;