mirror of https://github.com/python/cpython
gh-87604: Avoid publishing list of active per-interpreter audit hooks via the gc module (GH-99373)
This commit is contained in:
parent
3d9431983a
commit
4e4b13e8f6
|
@ -450,6 +450,17 @@ def test_syslog():
|
|||
syslog.closelog()
|
||||
|
||||
|
||||
def test_not_in_gc():
|
||||
import gc
|
||||
|
||||
hook = lambda *a: None
|
||||
sys.addaudithook(hook)
|
||||
|
||||
for o in gc.get_objects():
|
||||
if isinstance(o, list):
|
||||
assert hook not in o
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from test.support import suppress_msvcrt_asserts
|
||||
|
||||
|
|
|
@ -222,6 +222,11 @@ class AuditTest(unittest.TestCase):
|
|||
('syslog.closelog', '', '')]
|
||||
)
|
||||
|
||||
def test_not_in_gc(self):
|
||||
returncode, _, stderr = self.run_python("test_not_in_gc")
|
||||
if returncode:
|
||||
self.fail(stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Avoid publishing list of active per-interpreter audit hooks via the
|
||||
:mod:`gc` module
|
|
@ -431,6 +431,8 @@ sys_addaudithook_impl(PyObject *module, PyObject *hook)
|
|||
if (interp->audit_hooks == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
/* Avoid having our list of hooks show up in the GC module */
|
||||
PyObject_GC_UnTrack(interp->audit_hooks);
|
||||
}
|
||||
|
||||
if (PyList_Append(interp->audit_hooks, hook) < 0) {
|
||||
|
|
Loading…
Reference in New Issue