From df36cf12d925231fdabb9aac2208508e7955367b Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Wed, 22 Jul 2026 17:08:46 +0200 Subject: [PATCH] [3.15] gh-154137: Fix handle leak in test_winapi (GH-154201) (#154202) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Make sure that events handles are closed. (cherry picked from commit 1f9d20bbd4fed601e7caf76a12e52d35c8ae2b14) Co-authored-by: Victor Stinner Co-authored-by: Łukasz Langa --- Lib/test/test_winapi.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/test_winapi.py b/Lib/test/test_winapi.py index a1c0b80d47e4..0ae03a3bf505 100644 --- a/Lib/test/test_winapi.py +++ b/Lib/test/test_winapi.py @@ -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) -- 2.47.3