#include "src/smpi/include/smpi_actor.hpp"
#include "xbt/config.hpp"
+#include <algorithm>
#include <cfloat> /* DBL_MAX */
#include <dlfcn.h>
#include <fcntl.h>
static int smpi_run_entry_point(smpi_entry_point_type entry_point, std::vector<std::string> args)
{
- char noarg[] = {'\0'};
- int argc = args.size();
- char** argv = new char*[argc + 1];
- for (int i = 0; i != argc; ++i)
- argv[i] = args[i].empty() ? noarg : xbt_strdup(&args[i].front());
- argv[argc] = nullptr;
+ // copy C strings, we need them writable
+ std::vector<char*>* args4argv = new std::vector<char*>(args.size());
+ std::transform(begin(args), end(args), begin(*args4argv), [](const std::string& s) { return xbt_strdup(s.c_str()); });
+
+ // take a copy of args4argv to keep reference of the allocated strings
+ const std::vector<char*> args2str(*args4argv);
+ int argc = args4argv->size();
+ args4argv->push_back(nullptr);
+ char** argv = args4argv->data();
+
simgrid::smpi::ActorExt::init(&argc, &argv);
#if SMPI_IFORT
for_rtl_init_ (&argc, argv);
#if SMPI_IFORT
for_rtl_finish_ ();
+#else
+ for (char* s : args2str)
+ xbt_free(s);
+ delete args4argv;
#endif
- for (int i = 0; i != argc; ++i)
- xbt_free(argv[i]);
- xbt_free(argv);
if (res != 0){
XBT_WARN("SMPI process did not return 0. Return value : %d", res);
if (smpi_exit_status == 0)