summaryrefslogtreecommitdiffstats
path: root/base/process_util_win.cc
diff options
context:
space:
mode:
authorstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-09 19:28:41 +0000
committerstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-09 19:28:41 +0000
commitcd4fd156aba80ddffd3fffd8e2d8703247181fe0 (patch)
tree1f4b2dc5f58e5f534b033f71e0e48cc5549c6732 /base/process_util_win.cc
parenta6309f8198825442d77f0fc9aa70c82ae5dd6d04 (diff)
downloadchromium_src-cd4fd156aba80ddffd3fffd8e2d8703247181fe0.zip
chromium_src-cd4fd156aba80ddffd3fffd8e2d8703247181fe0.tar.gz
chromium_src-cd4fd156aba80ddffd3fffd8e2d8703247181fe0.tar.bz2
Fix the windows implementation of KillProcess and WaitForSingleProcess to not close the process handle that they do not own.
Review URL: http://codereview.chromium.org/24004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_win.cc')
-rw-r--r--base/process_util_win.cc35
1 files changed, 19 insertions, 16 deletions
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index bb0e626..2edf5ec 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -160,17 +160,20 @@ bool LaunchApp(const CommandLine& cl,
// Attempts to kill the process identified by the given process
// entry structure, giving it the specified exit code.
// Returns true if this is successful, false otherwise.
-bool KillProcess(int process_id, int exit_code, bool wait) {
+bool KillProcessById(DWORD process_id, int exit_code, bool wait) {
HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE,
FALSE, // Don't inherit handle
process_id);
- if (process)
- return KillProcess(process, exit_code, wait);
- return false;
+ if (!process)
+ return false;
+
+ bool ret = KillProcess(process, exit_code, wait);
+ CloseHandle(process);
+ return ret;
}
-bool KillProcess(HANDLE process, int exit_code, bool wait) {
- bool result = !!TerminateProcess(process, exit_code);
+bool KillProcess(ProcessHandle process, int exit_code, bool wait) {
+ bool result = (TerminateProcess(process, exit_code) != FALSE);
if (result && wait) {
// The process may not end immediately due to pending I/O
if (WAIT_OBJECT_0 != WaitForSingleObject(process, 60 * 1000))
@@ -178,7 +181,6 @@ bool KillProcess(HANDLE process, int exit_code, bool wait) {
} else {
DLOG(ERROR) << "Unable to terminate process: " << GetLastError();
}
- CloseHandle(process);
return result;
}
@@ -252,12 +254,12 @@ bool WaitForExitCode(ProcessHandle handle, int* exit_code) {
}
NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name,
- const ProcessFilter* filter) :
- started_iteration_(false),
- executable_name_(executable_name),
- filter_(filter) {
- snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- }
+ const ProcessFilter* filter)
+ : started_iteration_(false),
+ executable_name_(executable_name),
+ filter_(filter) {
+ snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+}
NamedProcessIterator::~NamedProcessIterator() {
CloseHandle(snapshot_);
@@ -315,8 +317,10 @@ bool KillProcesses(const std::wstring& executable_name, int exit_code,
const ProcessEntry* entry;
NamedProcessIterator iter(executable_name, filter);
- while (entry = iter.NextProcessEntry())
- result = KillProcess((*entry).th32ProcessID, exit_code, true) && result;
+ while (entry = iter.NextProcessEntry()) {
+ if (!KillProcessById((*entry).th32ProcessID, exit_code, true))
+ result = false;
+ }
return result;
}
@@ -346,7 +350,6 @@ bool WaitForProcessesToExit(const std::wstring& executable_name,
bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) {
bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_OBJECT_0;
- CloseHandle(handle);
return retval;
}