Skip to content

Commit a37b105

Browse files
[3.14] gh-148653: Fix reference leaks in test_marshal introduced in gh-148698 (GH-148725) (GH-148727)
(cherry picked from commit 7ce737e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent d496c63 commit a37b105

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Lib/test/test_marshal.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ def f():
357357
code = f.__code__
358358
a = []
359359
code = code.replace(co_consts=code.co_consts + (a,))
360+
# This test creates a reference loop which leads to reference leaks,
361+
# so we need to break the loop manually. See gh-148722.
362+
self.addCleanup(a.clear)
360363
a.append(code)
361364
for v in range(marshal.version + 1):
362365
self.assertRaises(ValueError, marshal.dumps, code, v)
@@ -404,10 +407,12 @@ def test_loads_abnormal_reference_loops(self):
404407
self.assertIs(a[0][None], a)
405408

406409
# Direct self-reference which cannot be created in Python.
407-
data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,)
408-
a = marshal.loads(data)
409-
self.assertIsInstance(a, tuple)
410-
self.assertIs(a[0], a)
410+
# This creates a reference loop which cannot be collected.
411+
if False:
412+
data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,)
413+
a = marshal.loads(data)
414+
self.assertIsInstance(a, tuple)
415+
self.assertIs(a[0], a)
411416

412417
# Direct self-references which cannot be created in Python
413418
# because of unhashability.

0 commit comments

Comments
 (0)