Skip to content

Commit 1076567

Browse files
committed
CloseHandle should be in a finally block in case MapViewOfFile fails.
1 parent eec4bb1 commit 1076567

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Lib/multiprocessing/shared_memory.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ def __init__(self, name, flags=None, mode=384, size=0, read_only=False):
9898
h_map = kernel32.OpenFileMappingW(FILE_MAP_READ, False, name)
9999
except OSError as ose:
100100
raise ExistentialError(*ose.args)
101-
p_buf = kernel32.MapViewOfFile(h_map, FILE_MAP_READ, 0, 0, 0)
102-
kernel32.CloseHandle(h_map)
101+
try:
102+
p_buf = kernel32.MapViewOfFile(h_map, FILE_MAP_READ, 0, 0, 0)
103+
finally:
104+
kernel32.CloseHandle(h_map)
103105
mbi = MEMORY_BASIC_INFORMATION()
104106
kernel32.VirtualQuery(p_buf, ctypes.byref(mbi), mmap.PAGESIZE)
105107
size = mbi.RegionSize

0 commit comments

Comments
 (0)