Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitb50b6f9

Browse files
[3.8]gh-87604: Avoid publishing list of active per-interpreter audit hooks via the gc module (GH-99373) (GH-99661)
(cherry picked from commit7b98207)Co-authored-by: Steve Dower <steve.dower@python.org>
1 parent82ca283 commitb50b6f9

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

‎Lib/test/audit-tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,17 @@ def hook(event, args):
341341
gc.get_referents(y)
342342

343343

344+
deftest_not_in_gc():
345+
importgc
346+
347+
hook=lambda*a:None
348+
sys.addaudithook(hook)
349+
350+
foroingc.get_objects():
351+
ifisinstance(o,list):
352+
asserthooknotino
353+
354+
344355
if__name__=="__main__":
345356
fromtest.supportimportsuppress_msvcrt_asserts
346357

‎Lib/test/test_audit.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ def test_gc(self):
127127
["gc.get_objects","gc.get_referrers","gc.get_referents"]
128128
)
129129

130+
deftest_not_in_gc(self):
131+
returncode,_,stderr=self.run_python("test_not_in_gc")
132+
ifreturncode:
133+
self.fail(stderr)
134+
130135

131136
if__name__=="__main__":
132137
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Avoid publishing list of active per-interpreter audit hooks via the
2+
:mod:`gc` module

‎Python/sysmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ sys_addaudithook_impl(PyObject *module, PyObject *hook)
356356
if (is->audit_hooks==NULL) {
357357
returnNULL;
358358
}
359+
/* Avoid having our list of hooks show up in the GC module */
360+
PyObject_GC_UnTrack(is->audit_hooks);
359361
}
360362

361363
if (PyList_Append(is->audit_hooks,hook)<0) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp