提交 c2c876f7 编写于 作者: K Krzysztof Binias 提交者: Tao Luo

Fix memory leak in test (#18622)

* Fix memory leak in test

test=develop

* Fix memory leak in test
test=develop

* Fix memory leak in test
test=develop

* Pull out vars of the loops
test=develop
上级 ee2f296e
......@@ -61,23 +61,27 @@ int main(int argc, char** argv) {
undefok.push_back("initial_cpu_memory_in_mb");
#endif
char* env_str = nullptr;
if (envs.size() > 0) {
std::string env_string = "--tryfromenv=";
for (auto t : envs) {
env_string += t + ",";
}
env_string = env_string.substr(0, env_string.length() - 1);
new_argv.push_back(strdup(env_string.c_str()));
env_str = strdup(env_string.c_str());
new_argv.push_back(env_str);
VLOG(1) << "gtest env_string:" << env_string;
}
char* undefok_str = nullptr;
if (undefok.size() > 0) {
std::string undefok_string = "--undefok=";
for (auto t : undefok) {
undefok_string += t + ",";
}
undefok_string = undefok_string.substr(0, undefok_string.length() - 1);
new_argv.push_back(strdup(undefok_string.c_str()));
undefok_str = strdup(undefok_string.c_str());
new_argv.push_back(undefok_str);
VLOG(1) << "gtest undefok_string:" << undefok_string;
}
......@@ -85,5 +89,11 @@ int main(int argc, char** argv) {
char** new_argv_address = new_argv.data();
google::ParseCommandLineFlags(&new_argc, &new_argv_address, false);
paddle::framework::InitDevices(true);
return RUN_ALL_TESTS();
int ret = RUN_ALL_TESTS();
if (env_str) free(env_str);
if (undefok_str) free(undefok_str);
return ret;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册