]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-154137: Fix handle leak in test_winapi (GH-154201) (#154203)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 22 Jul 2026 12:21:16 +0000 (14:21 +0200)
committerGitHub <noreply@github.com>
Wed, 22 Jul 2026 12:21:16 +0000 (14:21 +0200)
gh-154137: Fix handle leak in test_winapi (GH-154201)

Make sure that events handles are closed.
(cherry picked from commit 1f9d20bbd4fed601e7caf76a12e52d35c8ae2b14)

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/test_winapi.py

index e64208330ad2f9e91b1efd0f95a7494aeff7736d..b4a2d92c08a236ad9b05da180e26b9af8c7dcb6e 100644 (file)
@@ -11,9 +11,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)
@@ -41,6 +48,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)