- simgrid::smpi::F2C::lookup()->size() - simgrid::smpi::F2C::get_num_default_handles());
- int n = simgrid::config::get_value<int>("smpi/list-leaks");
- for (auto const& p : *simgrid::smpi::F2C::lookup()) {
- static int printed = 0;
- if (printed >= n)
- break;
- if (p.first >= simgrid::smpi::F2C::get_num_default_handles()) {
- XBT_WARN("Leak %p of type %s", p.second, boost::core::demangle(typeid(*(p.second)).name()).c_str());
- printed++;
+ handles.size());
+ auto max = static_cast<unsigned long>(simgrid::config::get_value<int>("smpi/list-leaks"));
+ if (max > 0) { // we cannot trust F2C::lookup()->size() > F2C::get_num_default_handles() because some default
+ // handles are already freed at this point
+ std::sort(handles.begin(), handles.end(), [](auto const& a, auto const& b) { return a.first < b.first; });
+ bool truncate = max < handles.size();
+ if (truncate)
+ handles.resize(max);
+ bool printed_advice=false;
+ for (const auto& p : handles) {
+ if (xbt_log_no_loc || p.second->call_location().empty()) {
+ if (!printed_advice){
+ XBT_INFO("To get more information (location of allocations), compile your code with -trace-call-location flag of smpicc/f90");
+ printed_advice=true;
+ }
+ XBT_INFO("Leaked handle of type %s", p.second->name().c_str());
+ } else {
+ XBT_INFO("Leaked handle of type %s at %s", p.second->name().c_str(), p.second->call_location().c_str());
+ }