Fix the ams crash caused by list erase.

Signed-off-by: jsj <jinsenjun@huawei.com>
This commit is contained in:
jsj
2022-01-07 03:55:12 +00:00
parent eb78f61507
commit 8947bf6eee
2 changed files with 9 additions and 9 deletions
@@ -647,13 +647,13 @@ private:
bool process_exist(pid_t &pid);
/**
* CheckALLProcessExist, Determine whether all processes exist .
* CheckAllProcessExist, Determine whether all processes exist .
*
* @param pids, process number collection to exit.
*
* @return true, Returns that a process exists and all other processes do not exist.
*/
bool CheckALLProcessExist(std::list<pid_t> &pids);
bool CheckAllProcessExist(std::list<pid_t> &pids);
/**
* SystemTimeMillis, Get system time.
@@ -440,7 +440,7 @@ bool AppMgrServiceInner::WaitForRemoteProcessExit(std::list<pid_t> &pids, const
{
int64_t delayTime = SystemTimeMillis() - startTime;
while (delayTime < KILL_PROCESS_TIMEOUT_MICRO_SECONDS) {
if (CheckALLProcessExist(pids)) {
if (CheckAllProcessExist(pids)) {
return true;
}
usleep(KILL_PROCESS_DELAYTIME_MICRO_SECONDS);
@@ -479,18 +479,18 @@ bool AppMgrServiceInner::process_exist(pid_t &pid)
return false;
}
bool AppMgrServiceInner::CheckALLProcessExist(std::list<pid_t> &pids)
bool AppMgrServiceInner::CheckAllProcessExist(std::list<pid_t> &pids)
{
for (auto iter = pids.begin(); iter != pids.end(); ) {
if (!process_exist(*iter) && pids.size() != 0) {
pids.erase(iter);
if (pids.empty()) {
return true;
}
if (!process_exist(*iter)) {
iter = pids.erase(iter);
} else {
iter++;
}
}
if (pids.empty()) {
return true;
}
return false;
}