diff --git a/paddle/fluid/platform/init.cc b/paddle/fluid/platform/init.cc index 4113379f5b40c2174eb96c76696a799b171d6d15..8ec57d77192565bd42c771288f5ae4c56160e6a2 100644 --- a/paddle/fluid/platform/init.cc +++ b/paddle/fluid/platform/init.cc @@ -50,7 +50,7 @@ std::once_flag glog_init_flag; std::once_flag p2p_init_flag; std::once_flag glog_warning_once_flag; -bool InitGflags(std::vector argv) { +bool InitGflags(std::vector args) { bool successed = false; std::call_once(gflags_init_flag, [&]() { FLAGS_logtostderr = true; @@ -59,20 +59,23 @@ bool InitGflags(std::vector argv) { // commandline strings from idx 1. // The reason is, it assumes that the first one (idx 0) is // the filename of executable file. - argv.insert(argv.begin(), "dummy"); - int argc = argv.size(); - char **arr = new char *[argv.size()]; + args.insert(args.begin(), "dummy"); + std::vector argv; std::string line; - for (size_t i = 0; i < argv.size(); i++) { - arr[i] = &argv[i][0]; - line += argv[i]; + int argc = args.size(); + for (auto &arg : args) { + argv.push_back(const_cast(arg.data())); + line += arg; line += ' '; } VLOG(1) << "Before Parse: argc is " << argc << ", Init commandline: " << line; + + char **arr = argv.data(); google::ParseCommandLineFlags(&argc, &arr, true); - VLOG(1) << "After Parse: argc is " << argc; successed = true; + + VLOG(1) << "After Parse: argc is " << argc; }); return successed; }