Skip to content

Commit ccbed00

Browse files
Fix reference leaks in test_marshal introduced in gh-148698
1 parent d61fcf8 commit ccbed00

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)
@@ -410,10 +413,12 @@ def test_loads_abnormal_reference_loops(self):
410413
self.assertIs(a[0][None], a)
411414

412415
# Direct self-reference which cannot be created in Python.
413-
data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,)
414-
a = marshal.loads(data)
415-
self.assertIsInstance(a, tuple)
416-
self.assertIs(a[0], a)
416+
# This creates a reference loop which cannot be collected.
417+
if False:
418+
data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,)
419+
a = marshal.loads(data)
420+
self.assertIsInstance(a, tuple)
421+
self.assertIs(a[0], a)
417422

418423
# Direct self-references which cannot be created in Python
419424
# because of unhashability.

0 commit comments

Comments
 (0)