summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2022-11-25 17:39:48 (GMT)
committerGitHub <noreply@github.com>2022-11-25 17:39:48 (GMT)
commit85c128e34daec7625b74746e127afa25888ccde1 (patch)
tree81f9e08d696f6e61ecab4863e5cf345b9ee56906 /Lib/multiprocessing
parent8749121b07f48994ea47f2e7ff75fb13c13953f6 (diff)
downloadcpython-85c128e34daec7625b74746e127afa25888ccde1.zip
cpython-85c128e34daec7625b74746e127afa25888ccde1.tar.gz
cpython-85c128e34daec7625b74746e127afa25888ccde1.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.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r--Lib/multiprocessing/shared_memory.py5
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