Skip to content
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 Lib/test/audit-tests.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -440,6 +440,17 @@ def hook(event, args):
syslog.closelog()


deftest_not_in_gc():
importgc

hook=lambda*a: None
sys.addaudithook(hook)

foroingc.get_objects():
ifisinstance(o, list):
asserthooknotino


if__name__=="__main__":
fromtest.supportimportsuppress_msvcrt_asserts

Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_audit.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,6 +209,11 @@ def test_syslog(self):
('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()
Original file line numberDiff line numberDiff 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 Python/sysmodule.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -440,6 +440,8 @@ sys_addaudithook_impl(PyObject *module, PyObject *hook)
if (interp->audit_hooks==NULL){
returnNULL;
}
/* 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){
Expand Down