From 5ec89fa2cffd6582b311b1861e4fbd8af71bc5ae Mon Sep 17 00:00:00 2001 From: "jcampan@chromium.org" <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> Date: Wed, 22 Apr 2009 20:19:10 +0000 Subject: 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 --- base/process_util_win.cc | 14 +++++++------- 1 file 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; } -- cgit v1.1