Skip to content

Commit 0643f4d

Browse files
[3.14] gh-154137: Fix handle leak in test_winapi (GH-154201) (#154203)
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 71fa9b4 commit 0643f4d

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
@@ -11,9 +11,16 @@
1111
MAXIMUM_WAIT_OBJECTS = 64
1212
MAXIMUM_BATCHED_WAIT_OBJECTS = (MAXIMUM_WAIT_OBJECTS - 1) ** 2
1313

14+
15+
def close_events(events):
16+
for handle in events:
17+
_winapi.CloseHandle(handle)
18+
19+
1420
class WinAPIBatchedWaitForMultipleObjectsTests(unittest.TestCase):
1521
def _events_waitall_test(self, n):
1622
evts = [_winapi.CreateEventW(0, False, False, None) for _ in range(n)]
23+
self.addCleanup(close_events, evts)
1724

1825
with self.assertRaises(TimeoutError):
1926
_winapi.BatchedWaitForMultipleObjects(evts, True, 100)
@@ -41,6 +48,7 @@ def _events_waitall_test(self, n):
4148

4249
def _events_waitany_test(self, n):
4350
evts = [_winapi.CreateEventW(0, False, False, None) for _ in range(n)]
51+
self.addCleanup(close_events, evts)
4452

4553
with self.assertRaises(TimeoutError):
4654
_winapi.BatchedWaitForMultipleObjects(evts, False, 100)

0 commit comments

Comments
 (0)