]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154137: Fix handle leak in test_winapi (#154201)
authorVictor Stinner <vstinner@python.org>
Sun, 19 Jul 2026 22:19:32 +0000 (00:19 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Jul 2026 22:19:32 +0000 (00:19 +0200)
Make sure that events handles are closed.

Lib/test/test_winapi.py

index a1c0b80d47e4d444f89f017eb9c8fa31ca50394d..0ae03a3bf505f73a4cd2c75db1adfa9a661ec8d5 100644 (file)
@@ -12,9 +12,16 @@ _winapi = import_helper.import_module('_winapi', required_on=['win'])
 MAXIMUM_WAIT_OBJECTS = 64
 MAXIMUM_BATCHED_WAIT_OBJECTS = (MAXIMUM_WAIT_OBJECTS - 1) ** 2
 
+
+def close_events(events):
+    for handle in events:
+        _winapi.CloseHandle(handle)
+
+
 class WinAPIBatchedWaitForMultipleObjectsTests(unittest.TestCase):
     def _events_waitall_test(self, n):
         evts = [_winapi.CreateEventW(0, False, False, None) for _ in range(n)]
+        self.addCleanup(close_events, evts)
 
         with self.assertRaises(TimeoutError):
             _winapi.BatchedWaitForMultipleObjects(evts, True, 100)
@@ -42,6 +49,7 @@ class WinAPIBatchedWaitForMultipleObjectsTests(unittest.TestCase):
 
     def _events_waitany_test(self, n):
         evts = [_winapi.CreateEventW(0, False, False, None) for _ in range(n)]
+        self.addCleanup(close_events, evts)
 
         with self.assertRaises(TimeoutError):
             _winapi.BatchedWaitForMultipleObjects(evts, False, 100)