https://github.com/python/cpython/commit/a60194609a956f51311746a8c9e68a4477a6c7f3 commit: a60194609a956f51311746a8c9e68a4477a6c7f3 branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka <[email protected]> date: 2026-04-18T12:34:25Z summary:
[3.13] gh-148653: Fix reference leaks in test_marshal introduced in gh-148698 (GH-148725) (GH-148728) (cherry picked from commit 7ce737ea11919aebf7eef174f910759e74d0ea50) Co-authored-by: Serhiy Storchaka <[email protected]> files: M Lib/test/test_marshal.py diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py index 3965dd5332421b..1a4fde1e0a70f3 100644 --- a/Lib/test/test_marshal.py +++ b/Lib/test/test_marshal.py @@ -350,6 +350,9 @@ def f(): code = f.__code__ a = [] code = code.replace(co_consts=code.co_consts + (a,)) + # This test creates a reference loop which leads to reference leaks, + # so we need to break the loop manually. See gh-148722. + self.addCleanup(a.clear) a.append(code) for v in range(marshal.version + 1): self.assertRaises(ValueError, marshal.dumps, code, v) @@ -381,10 +384,12 @@ def test_loads_abnormal_reference_loops(self): self.assertIs(a[0][None], a) # Direct self-reference which cannot be created in Python. - data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,) - a = marshal.loads(data) - self.assertIsInstance(a, tuple) - self.assertIs(a[0], a) + # This creates a reference loop which cannot be collected. + if False: + data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,) + a = marshal.loads(data) + self.assertIsInstance(a, tuple) + self.assertIs(a[0], a) # Direct self-references which cannot be created in Python # because of unhashability. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
