summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorTim Golden <mail@timgolden.me.uk>2010-08-06 13:03:56 (GMT)
committerTim Golden <mail@timgolden.me.uk>2010-08-06 13:03:56 (GMT)
commitaf5ac3974b7dbf824c8ed560c7dd5588fab0d419 (patch)
treeee9b31e845c44c2645e177efdd2e50b5f3f296e1 /PC
parent2e3d539ce2d4b91e3353e890858f8f8de6215d25 (diff)
downloadcpython-af5ac3974b7dbf824c8ed560c7dd5588fab0d419.zip
cpython-af5ac3974b7dbf824c8ed560c7dd5588fab0d419.tar.gz
cpython-af5ac3974b7dbf824c8ed560c7dd5588fab0d419.tar.bz2
Issue #3210: Ensure stdio handles are closed if CreateProcess fails
Diffstat (limited to 'PC')
-rw-r--r--PC/_subprocess.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/PC/_subprocess.c b/PC/_subprocess.c
index 5132a5e..2a3207b 100644
--- a/PC/_subprocess.c
+++ b/PC/_subprocess.c
@@ -429,6 +429,7 @@ sp_CreateProcess(PyObject* self, PyObject* args)
PyObject* env_mapping;
Py_UNICODE* current_directory;
PyObject* startup_info;
+ DWORD error;
if (! PyArg_ParseTuple(args, "ZZOOiiOZO:CreateProcess",
&application_name,
@@ -478,8 +479,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),