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

Unified Diff: base/process_util_win.cc

Issue 9700038: ScopedProcessInformation protects against process/thread handle leaks from CreateProcess calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove changes from another CL. Created 8 years, 9 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
Index: base/process_util_win.cc
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index d640d683e3a5b805f7d2fbedf573a35a3bcfb8b1..d9483d4042e0608ff22d16c7dc904879de465ef7 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -23,6 +23,7 @@
#include "base/sys_info.h"
#include "base/win/object_watcher.h"
#include "base/win/scoped_handle.h"
+#include "base/win/scoped_process_information.h"
#include "base/win/windows_version.h"
// userenv.dll is required for CreateEnvironmentBlock().
@@ -306,7 +307,6 @@ bool LaunchProcess(const string16& cmdline,
startup_info.lpDesktop = L"";
startup_info.dwFlags = STARTF_USESHOWWINDOW;
startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW;
- PROCESS_INFORMATION process_info;
DWORD flags = 0;
@@ -319,6 +319,8 @@ bool LaunchProcess(const string16& cmdline,
flags |= CREATE_BREAKAWAY_FROM_JOB;
}
+ base::win::ScopedProcessInformation process_info;
+
if (options.as_user) {
flags |= CREATE_UNICODE_ENVIRONMENT;
void* enviroment_block = NULL;
@@ -331,7 +333,7 @@ bool LaunchProcess(const string16& cmdline,
const_cast<wchar_t*>(cmdline.c_str()),
NULL, NULL, options.inherit_handles, flags,
enviroment_block, NULL, &startup_info,
- &process_info);
+ process_info.Receive());
DestroyEnvironmentBlock(enviroment_block);
if (!launched)
return false;
@@ -339,34 +341,29 @@ bool LaunchProcess(const string16& cmdline,
if (!CreateProcess(NULL,
const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL,
options.inherit_handles, flags, NULL, NULL,
- &startup_info, &process_info)) {
+ &startup_info, process_info.Receive())) {
return false;
}
}
if (options.job_handle) {
if (0 == AssignProcessToJobObject(options.job_handle,
- process_info.hProcess)) {
+ process_info.Get().hProcess)) {
DLOG(ERROR) << "Could not AssignProcessToObject.";
- KillProcess(process_info.hProcess, kProcessKilledExitCode, true);
+ KillProcess(process_info.Get().hProcess, kProcessKilledExitCode, true);
return false;
}
- ResumeThread(process_info.hThread);
+ ResumeThread(process_info.Get().hThread);
}
- // Handles must be closed or they will leak.
- CloseHandle(process_info.hThread);
-
if (options.wait)
- WaitForSingleObject(process_info.hProcess, INFINITE);
+ WaitForSingleObject(process_info.Get().hProcess, INFINITE);
// If the caller wants the process handle, we won't close it.
- if (process_handle) {
- *process_handle = process_info.hProcess;
- } else {
- CloseHandle(process_info.hProcess);
- }
+ if (process_handle)
+ *process_handle = process_info.TakeProcessHandle();
+
return true;
}
« no previous file with comments | « base/base.gypi ('k') | base/win/scoped_handle.h » ('j') | base/win/scoped_handle.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698