summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing/reduction.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-06-27 09:40:24 (GMT)
committerGitHub <noreply@github.com>2018-06-27 09:40:24 (GMT)
commit2cc9d21fffb8146d30e6fb4221e32410ba4b4ab7 (patch)
treea64c215f6670bd22695f9d1855956aa3d57a87e1 /Lib/multiprocessing/reduction.py
parentf15f66d275d1166839312c9ff3a67c00b486c7d6 (diff)
downloadcpython-2cc9d21fffb8146d30e6fb4221e32410ba4b4ab7.zip
cpython-2cc9d21fffb8146d30e6fb4221e32410ba4b4ab7.tar.gz
cpython-2cc9d21fffb8146d30e6fb4221e32410ba4b4ab7.tar.bz2
bpo-33929: multiprocessing: fix handle leak on race condition (GH-7921)
Fix a race condition in Popen of multiprocessing.popen_spawn_win32. The child process now duplicates the read end of pipe instead of "stealing" it. Previously, the read end of pipe was "stolen" by the child process, but it leaked a handle if the child process had been terminated before it could steal the handle from the parent process.
Diffstat (limited to 'Lib/multiprocessing/reduction.py')
-rw-r--r--Lib/multiprocessing/reduction.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/multiprocessing/reduction.py b/Lib/multiprocessing/reduction.py
index deca19c..473fd59 100644
--- a/Lib/multiprocessing/reduction.py
+++ b/Lib/multiprocessing/reduction.py
@@ -68,12 +68,16 @@ if sys.platform == 'win32':
__all__ += ['DupHandle', 'duplicate', 'steal_handle']
import _winapi
- def duplicate(handle, target_process=None, inheritable=False):
+ def duplicate(handle, target_process=None, inheritable=False,
+ *, source_process=None):
'''Duplicate a handle. (target_process is a handle not a pid!)'''
+ current_process = _winapi.GetCurrentProcess()
+ if source_process is None:
+ source_process = current_process
if target_process is None:
- target_process = _winapi.GetCurrentProcess()
+ target_process = current_process
return _winapi.DuplicateHandle(
- _winapi.GetCurrentProcess(), handle, target_process,
+ source_process, handle, target_process,
0, inheritable, _winapi.DUPLICATE_SAME_ACCESS)
def steal_handle(source_pid, handle):