Skip to content

Commit 02e5880

Browse files
[3.13] gh-154137: Fix handle leak in test_winapi (GH-154201) (#154204)
gh-154137: Fix handle leak in test_winapi (GH-154201) Make sure that events handles are closed. (cherry picked from commit 1f9d20b) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 68dd540 commit 02e5880

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Lib/test/test_winapi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@
1414
MAXIMUM_WAIT_OBJECTS = 64
1515
MAXIMUM_BATCHED_WAIT_OBJECTS = (MAXIMUM_WAIT_OBJECTS - 1) ** 2
1616

17+
18+
def close_events(events):
19+
for handle in events:
20+
_winapi.CloseHandle(handle)
21+
22+
1723
class WinAPIBatchedWaitForMultipleObjectsTests(unittest.TestCase):
1824
def _events_waitall_test(self, n):
1925
evts = [_winapi.CreateEventW(0, False, False, None) for _ in range(n)]
26+
self.addCleanup(close_events, evts)
2027

2128
with self.assertRaises(TimeoutError):
2229
_winapi.BatchedWaitForMultipleObjects(evts, True, 100)
@@ -44,6 +51,7 @@ def _events_waitall_test(self, n):
4451

4552
def _events_waitany_test(self, n):
4653
evts = [_winapi.CreateEventW(0, False, False, None) for _ in range(n)]
54+
self.addCleanup(close_events, evts)
4755

4856
with self.assertRaises(TimeoutError):
4957
_winapi.BatchedWaitForMultipleObjects(evts, False, 100)

0 commit comments

Comments
 (0)