mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.9] gh-87604: Avoid publishing list of active per-interpreter audit hooks via the gc module (GH-99373) (GH-99493)
This commit is contained in:
parent
c09dba57cf
commit
7b98207aa4
4 changed files with 20 additions and 0 deletions
|
|
@ -368,6 +368,17 @@ def hook(event, args):
|
||||||
gc.get_referents(y)
|
gc.get_referents(y)
|
||||||
|
|
||||||
|
|
||||||
|
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__":
|
if __name__ == "__main__":
|
||||||
from test.support import suppress_msvcrt_asserts
|
from test.support import suppress_msvcrt_asserts
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,11 @@ def test_gc(self):
|
||||||
["gc.get_objects", "gc.get_referrers", "gc.get_referents"]
|
["gc.get_objects", "gc.get_referrers", "gc.get_referents"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_not_in_gc(self):
|
||||||
|
returncode, _, stderr = self.run_python("test_not_in_gc")
|
||||||
|
if returncode:
|
||||||
|
self.fail(stderr)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Avoid publishing list of active per-interpreter audit hooks via the
|
||||||
|
:mod:`gc` module
|
||||||
|
|
@ -440,6 +440,8 @@ sys_addaudithook_impl(PyObject *module, PyObject *hook)
|
||||||
if (is->audit_hooks == NULL) {
|
if (is->audit_hooks == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/* Avoid having our list of hooks show up in the GC module */
|
||||||
|
PyObject_GC_UnTrack(is->audit_hooks);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyList_Append(is->audit_hooks, hook) < 0) {
|
if (PyList_Append(is->audit_hooks, hook) < 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue