[3.11] bpo-40882: Fix a memory leak in SharedMemory on Windows (GH-20684) (#99973)

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 85c128e34d)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
Luke Garland 2022-12-05 05:38:25 -07:00 committed by GitHub
parent 7f2bcc7aaa
commit 374b0a2ace
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 2 deletions

View file

@ -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