Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 11 Lib/test/audit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ def hook(event, args):
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__":
from test.support import suppress_msvcrt_asserts

Expand Down
5 changes: 5 additions & 0 deletions 5 Lib/test/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def test_gc(self):
["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__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Avoid publishing list of active per-interpreter audit hooks via the
:mod:`gc` module
2 changes: 2 additions & 0 deletions 2 Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ sys_addaudithook_impl(PyObject *module, PyObject *hook)
if (is->audit_hooks == 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) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.