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

Unified Diff: chrome/installer/util/product.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: chrome/installer/util/product.cc
diff --git a/chrome/installer/util/product.cc b/chrome/installer/util/product.cc
index f2ab2a788330963eebf10fb394c7a0296b1271c4..0e7bbdc6bdb5a631bcceb305fc1ad03f178ee2dd 100644
--- a/chrome/installer/util/product.cc
+++ b/chrome/installer/util/product.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/process_util.h"
#include "base/win/registry.h"
+#include "base/win/scoped_process_information.h"
#include "chrome/installer/util/chrome_browser_operations.h"
#include "chrome/installer/util/chrome_browser_sxs_operations.h"
#include "chrome/installer/util/chrome_frame_operations.h"
@@ -78,22 +79,20 @@ bool Product::LaunchChromeAndWait(const FilePath& application_path,
bool success = false;
STARTUPINFOW si = { sizeof(si) };
- PROCESS_INFORMATION pi = {0};
+ base::win::ScopedProcessInformation pi;
// Create a writable copy of the command line string, since CreateProcess may
// modify the string (insert \0 to separate the program from the arguments).
std::wstring writable_command_line_string(cmd.GetCommandLineString());
if (!::CreateProcess(cmd.GetProgram().value().c_str(),
&writable_command_line_string[0],
NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL,
- &si, &pi)) {
+ &si, pi.Receive())) {
PLOG(ERROR) << "Failed to launch: " << cmd.GetCommandLineString();
} else {
- ::CloseHandle(pi.hThread);
-
- DWORD ret = ::WaitForSingleObject(pi.hProcess, INFINITE);
+ DWORD ret = ::WaitForSingleObject(pi.Get().hProcess, INFINITE);
DLOG_IF(ERROR, ret != WAIT_OBJECT_0)
<< "Unexpected return value from WaitForSingleObject: " << ret;
- if (::GetExitCodeProcess(pi.hProcess, &ret)) {
+ if (::GetExitCodeProcess(pi.Get().hProcess, &ret)) {
DCHECK(ret != STILL_ACTIVE);
success = true;
if (exit_code)
@@ -101,8 +100,6 @@ bool Product::LaunchChromeAndWait(const FilePath& application_path,
} else {
PLOG(ERROR) << "GetExitCodeProcess failed";
}
-
- ::CloseHandle(pi.hProcess);
}
return success;

Powered by Google App Engine
This is Rietveld 408576698