Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(843)

Unified Diff: base/process_util_win.cc

Issue 24004: Fix the windows implementation of KillProcess and WaitForSingleProcess to not... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util_unittest.cc ('k') | base/stats_table_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_win.cc
===================================================================
--- base/process_util_win.cc (revision 9385)
+++ base/process_util_win.cc (working copy)
@@ -160,17 +160,20 @@
// 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 @@
} else {
DLOG(ERROR) << "Unable to terminate process: " << GetLastError();
}
- CloseHandle(process);
return result;
}
@@ -252,12 +254,12 @@
}
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 @@
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 WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) {
bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_OBJECT_0;
- CloseHandle(handle);
return retval;
}
« no previous file with comments | « base/process_util_unittest.cc ('k') | base/stats_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698