File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -7503,20 +7503,24 @@ def close_fds(fds):
75037503@unittest .skipUnless (hasattr (sys , "gettotalrefcount" ),
75047504 "requires sys.gettotalrefcount()" )
75057505class AuditHookLeakTests (unittest .TestCase ):
7506- # gh-146245: Reference and buffer may leaks in audit hook's failures path .
7506+ # gh-146245: Reference and buffer leaks in audit hook failure paths .
75077507
75087508 def test_getaddrinfo_audit_hook_leak (self ):
75097509 code = textwrap .dedent ("""
75107510 import socket
75117511 import sys
75127512 import gc
7513- sys.addaudithook(lambda *a: (_ for _ in ()).throw(RuntimeError("audit")))
7513+
7514+ def hook(*args):
7515+ raise ValueError("audit")
7516+
7517+ sys.addaudithook(hook)
75147518 gc.collect()
75157519 before = sys.gettotalrefcount()
75167520 for _ in range(100):
75177521 try:
75187522 socket.getaddrinfo(None, 80)
7519- except RuntimeError :
7523+ except ValueError :
75207524 pass
75217525 gc.collect()
75227526 after = sys.gettotalrefcount()
@@ -7531,14 +7535,18 @@ def test_sendto_audit_hook_leak(self):
75317535 import socket
75327536 import sys
75337537 import gc
7538+
7539+ def hook(*args):
7540+ raise ValueError("audit")
7541+
75347542 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
7535- sys.addaudithook(lambda *a: (_ for _ in ()).throw(RuntimeError("audit")) )
7543+ sys.addaudithook(hook )
75367544 gc.collect()
75377545 before = sys.gettotalrefcount()
75387546 for _ in range(100):
75397547 try:
75407548 s.sendto(bytearray(b"x"), ("127.0.0.1", 80))
7541- except RuntimeError :
7549+ except ValueError :
75427550 pass
75437551 gc.collect()
75447552 after = sys.gettotalrefcount()
You can’t perform that action at this time.
0 commit comments