Bug 920397 part 1 - base::CloseProcessHandle() checks result in debug builds and is used everywhere a process handle is closed. r=bsmedberg

This commit is contained in:
Mark Hammond 2013-10-01 10:56:15 +10:00
parent 437f6053a9
commit 5bc55a78af
3 changed files with 9 additions and 5 deletions

View File

@ -99,7 +99,11 @@ bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle) {
}
void CloseProcessHandle(ProcessHandle process) {
CloseHandle(process);
// closing a handle twice on Windows can be catastrophic - after the first
// close the handle value may be reused, so the second close will kill that
// other new handle.
BOOL ok = CloseHandle(process);
DCHECK(ok);
}
// Helper for GetProcId()

View File

@ -12,7 +12,7 @@ namespace base {
void Process::Close() {
if (!process_)
return;
::CloseHandle(process_);
CloseProcessHandle(process_);
process_ = NULL;
}

View File

@ -42,7 +42,7 @@ class TimerExpiredTask : public Task, public base::ObjectWatcher::Delegate {
// watching. the process handle, so make sure it has stopped.
watcher_.StopWatching();
CloseHandle(process_);
base::CloseProcessHandle(process_);
process_ = NULL;
}
@ -85,13 +85,13 @@ void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process
if (!force) {
WaitForSingleObject(process, INFINITE);
CloseHandle(process);
base::CloseProcessHandle(process);
return;
}
// If already signaled, then we are done!
if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) {
CloseHandle(process);
base::CloseProcessHandle(process);
return;
}