diff options
author | Tim Golden <mail@timgolden.me.uk> | 2010-08-06 13:14:33 (GMT) |
---|---|---|
committer | Tim Golden <mail@timgolden.me.uk> | 2010-08-06 13:14:33 (GMT) |
commit | 90374f510223f559a70dcd762e223762d4f2ad85 (patch) | |
tree | 7557d5f2745bb82c9e9e394cfe5fb7f7d2304a66 /PC | |
parent | 3ad323ecaf9bbead043a8799d0a6189c6812b581 (diff) | |
download | cpython-90374f510223f559a70dcd762e223762d4f2ad85.zip cpython-90374f510223f559a70dcd762e223762d4f2ad85.tar.gz cpython-90374f510223f559a70dcd762e223762d4f2ad85.tar.bz2 |
Issue #3210: Ensure stdio handles are closed if CreateProcess fails
Diffstat (limited to 'PC')
-rw-r--r-- | PC/_subprocess.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/PC/_subprocess.c b/PC/_subprocess.c index 6780382..41a2498 100644 --- a/PC/_subprocess.c +++ b/PC/_subprocess.c @@ -425,6 +425,7 @@ sp_CreateProcess(PyObject* self, PyObject* args) PyObject* env_mapping; char* current_directory; PyObject* startup_info; + DWORD error; if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess", &application_name, @@ -474,8 +475,22 @@ sp_CreateProcess(PyObject* self, PyObject* args) Py_XDECREF(environment); - if (! result) - return PyErr_SetFromWindowsErr(GetLastError()); + if (! result) { + error = GetLastError(); + if(si.hStdInput != INVALID_HANDLE_VALUE) { + CloseHandle(si.hStdInput); + si.hStdInput = INVALID_HANDLE_VALUE; + } + if(si.hStdOutput != INVALID_HANDLE_VALUE) { + CloseHandle(si.hStdOutput); + si.hStdOutput = INVALID_HANDLE_VALUE; + } + if(si.hStdError != INVALID_HANDLE_VALUE) { + CloseHandle(si.hStdError); + si.hStdError = INVALID_HANDLE_VALUE; + } + return PyErr_SetFromWindowsErr(error); + } return Py_BuildValue("NNii", sp_handle_new(pi.hProcess), |