summaryrefslogtreecommitdiffstats
path: root/base/process_util_win.cc
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-22 20:19:10 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-22 20:19:10 +0000
commit5ec89fa2cffd6582b311b1861e4fbd8af71bc5ae (patch)
tree164a003f7d5fa5423aa9c2e34b86bb0055781b0c /base/process_util_win.cc
parentc714a16415946fe384b4ba341fc67697b9e79af3 (diff)
downloadchromium_src-5ec89fa2cffd6582b311b1861e4fbd8af71bc5ae.zip
chromium_src-5ec89fa2cffd6582b311b1861e4fbd8af71bc5ae.tar.gz
chromium_src-5ec89fa2cffd6582b311b1861e4fbd8af71bc5ae.tar.bz2
Ensures we don't leak handles in ProcessUtil::GetAppOutput.
TEST=Run base_unit_tests BUG=None Review URL: http://codereview.chromium.org/93030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14235 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_win.cc')
-rw-r--r--base/process_util_win.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index 3664c5c..13fec9a 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -203,6 +203,10 @@ bool GetAppOutput(const std::wstring& cmd_line, std::string* output) {
return false;
}
+ // Ensure we don't leak the handles.
+ ScopedHandle scoped_out_read(out_read);
+ ScopedHandle scoped_out_write(out_write);
+
// Ensure the read handle to the pipe for STDOUT is not inherited.
if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) {
NOTREACHED() << "Failed to disabled pipe inheritance";
@@ -231,10 +235,9 @@ bool GetAppOutput(const std::wstring& cmd_line, std::string* output) {
// We don't need the thread handle, close it now.
CloseHandle(proc_info.hThread);
- if (!CloseHandle(out_write)) {
- NOTREACHED() << "Failed to close std out write pipe.";
- return false;
- }
+ // Close our writing end of pipe now. Otherwise later read would not be able
+ // to detect end of child's output.
+ scoped_out_write.Close();
// Read output from the child process's pipe for STDOUT
const int kBufferSize = 1024;
@@ -252,9 +255,6 @@ bool GetAppOutput(const std::wstring& cmd_line, std::string* output) {
WaitForSingleObject(proc_info.hProcess, INFINITE);
CloseHandle(proc_info.hProcess);
- BOOL r = CloseHandle(out_read);
- DCHECK(r) << "Failed to close std out read pipe.";
-
return true;
}