|
2 | 2 | from unittest import mock |
3 | 3 | from test import support |
4 | 4 | from test.support import ( |
5 | | - cpython_only, is_apple, os_helper, refleak_helper, script_helper, socket_helper, threading_helper |
| 5 | + cpython_only, is_apple, os_helper, refleak_helper, socket_helper, threading_helper |
6 | 6 | ) |
7 | 7 | from test.support.import_helper import ensure_lazy_imports |
8 | 8 | import _thread as thread |
|
28 | 28 | import struct |
29 | 29 | import sys |
30 | 30 | import tempfile |
31 | | -import textwrap |
32 | 31 | import threading |
33 | 32 | import time |
34 | 33 | import traceback |
@@ -7499,65 +7498,6 @@ def close_fds(fds): |
7499 | 7498 | self.assertEqual(data, str(index).encode()) |
7500 | 7499 |
|
7501 | 7500 |
|
7502 | | -@support.requires_subprocess() |
7503 | | -@unittest.skipUnless(hasattr(sys, "gettotalrefcount"), |
7504 | | - "requires sys.gettotalrefcount()") |
7505 | | -class AuditHookLeakTests(unittest.TestCase): |
7506 | | - # gh-146245: Reference and buffer leaks in audit hook failure paths. |
7507 | | - |
7508 | | - def test_getaddrinfo_audit_hook_leak(self): |
7509 | | - code = textwrap.dedent(""" |
7510 | | - import socket |
7511 | | - import sys |
7512 | | - import gc |
7513 | | -
|
7514 | | - def hook(*args): |
7515 | | - raise ValueError("audit") |
7516 | | -
|
7517 | | - sys.addaudithook(hook) |
7518 | | - gc.collect() |
7519 | | - before = sys.gettotalrefcount() |
7520 | | - for _ in range(100): |
7521 | | - try: |
7522 | | - socket.getaddrinfo(None, 80) |
7523 | | - except ValueError: |
7524 | | - pass |
7525 | | - gc.collect() |
7526 | | - after = sys.gettotalrefcount() |
7527 | | - print(after - before) |
7528 | | - """) |
7529 | | - rc, out, err = script_helper.assert_python_ok("-c", code) |
7530 | | - leaked = int(out.strip()) |
7531 | | - self.assertAlmostEqual(leaked, 0, delta=2, msg=f"Leaked {leaked} references") |
7532 | | - |
7533 | | - def test_sendto_audit_hook_leak(self): |
7534 | | - code = textwrap.dedent(""" |
7535 | | - import socket |
7536 | | - import sys |
7537 | | - import gc |
7538 | | -
|
7539 | | - def hook(*args): |
7540 | | - raise ValueError("audit") |
7541 | | -
|
7542 | | - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
7543 | | - sys.addaudithook(hook) |
7544 | | - gc.collect() |
7545 | | - before = sys.gettotalrefcount() |
7546 | | - for _ in range(100): |
7547 | | - try: |
7548 | | - s.sendto(bytearray(b"x"), ("127.0.0.1", 80)) |
7549 | | - except ValueError: |
7550 | | - pass |
7551 | | - gc.collect() |
7552 | | - after = sys.gettotalrefcount() |
7553 | | - s.close() |
7554 | | - print(after - before) |
7555 | | - """) |
7556 | | - rc, out, err = script_helper.assert_python_ok("-c", code) |
7557 | | - leaked = int(out.strip()) |
7558 | | - self.assertAlmostEqual(leaked, 0, delta=2, msg=f"Leaked {leaked} references") |
7559 | | - |
7560 | | - |
7561 | 7501 | class FreeThreadingTests(unittest.TestCase): |
7562 | 7502 |
|
7563 | 7503 | def test_close_detach_race(self): |
|
0 commit comments