Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
af5ac397
Commit
af5ac397
authored
Aug 06, 2010
by
Tim Golden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #3210: Ensure stdio handles are closed if CreateProcess fails
parent
2e3d539c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
Lib/test/test_subprocess.py
Lib/test/test_subprocess.py
+20
-0
PC/_subprocess.c
PC/_subprocess.c
+17
-2
No files found.
Lib/test/test_subprocess.py
View file @
af5ac397
...
...
@@ -544,6 +544,26 @@ class ProcessTestCase(BaseTestCase):
output
=
subprocess
.
check_output
([
sys
.
executable
,
'-c'
,
code
])
self
.
assert_
(
output
.
startswith
(
b'Hello World!'
),
ascii
(
output
))
def
test_handles_closed_on_exception
(
self
):
# If CreateProcess exits with an error, ensure the
# duplicate output handles are released
ifhandle
,
ifname
=
mkstemp
()
ofhandle
,
ofname
=
mkstemp
()
efhandle
,
efname
=
mkstemp
()
try
:
subprocess
.
Popen
([
"*"
],
stdin
=
ifhandle
,
stdout
=
ofhandle
,
stderr
=
efhandle
)
except
OSError
:
os
.
close
(
ifhandle
)
os
.
remove
(
ifname
)
os
.
close
(
ofhandle
)
os
.
remove
(
ofname
)
os
.
close
(
efhandle
)
os
.
remove
(
efname
)
self
.
assertFalse
(
os
.
path
.
exists
(
ifname
))
self
.
assertFalse
(
os
.
path
.
exists
(
ofname
))
self
.
assertFalse
(
os
.
path
.
exists
(
efname
))
# context manager
class
_SuppressCoreFiles
(
object
):
...
...
PC/_subprocess.c
View file @
af5ac397
...
...
@@ -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
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment