diff options
author | Luke Garland <luke.garland01@gmail.com> | 2022-12-02 10:13:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-02 10:13:33 (GMT) |
commit | b027dd78bbdb66f2995bb898af304e66e5508bf6 (patch) | |
tree | 8186b09f41ea27821a8d8ff90152617c29af6736 /Lib/multiprocessing | |
parent | 64dae2efd5a083d342d744d40ca8d6ebb28bc771 (diff) | |
download | cpython-b027dd78bbdb66f2995bb898af304e66e5508bf6.zip cpython-b027dd78bbdb66f2995bb898af304e66e5508bf6.tar.gz cpython-b027dd78bbdb66f2995bb898af304e66e5508bf6.tar.bz2 |
bpo-40882: Fix a memory leak in SharedMemory on Windows (GH-20684)
In multiprocessing.shared_memory.SharedMemory(), the temporary view
returned by MapViewOfFile() should be unmapped when it is no longer
needed.
(cherry picked from commit 85c128e34daec7625b74746e127afa25888ccde1)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r-- | Lib/multiprocessing/shared_memory.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/multiprocessing/shared_memory.py b/Lib/multiprocessing/shared_memory.py index 881f200..9a1e5aa 100644 --- a/Lib/multiprocessing/shared_memory.py +++ b/Lib/multiprocessing/shared_memory.py @@ -173,7 +173,10 @@ class SharedMemory: ) finally: _winapi.CloseHandle(h_map) - size = _winapi.VirtualQuerySize(p_buf) + try: + size = _winapi.VirtualQuerySize(p_buf) + finally: + _winapi.UnmapViewOfFile(p_buf) self._mmap = mmap.mmap(-1, size, tagname=name) self._size = size |