Skip to content

Commit a601946

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

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
@@ -350,6 +350,9 @@ def f():
350350
code = f.__code__
351351
a = []
352352
code = code.replace(co_consts=code.co_consts + (a,))
353+
# This test creates a reference loop which leads to reference leaks,
354+
# so we need to break the loop manually. See gh-148722.
355+
self.addCleanup(a.clear)
353356
a.append(code)
354357
for v in range(marshal.version + 1):
355358
self.assertRaises(ValueError, marshal.dumps, code, v)
@@ -381,10 +384,12 @@ def test_loads_abnormal_reference_loops(self):
381384
self.assertIs(a[0][None], a)
382385

383386
# Direct self-reference which cannot be created in Python.
384-
data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,)
385-
a = marshal.loads(data)
386-
self.assertIsInstance(a, tuple)
387-
self.assertIs(a[0], a)
387+
# This creates a reference loop which cannot be collected.
388+
if False:
389+
data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,)
390+
a = marshal.loads(data)
391+
self.assertIsInstance(a, tuple)
392+
self.assertIs(a[0], a)
388393

389394
# Direct self-references which cannot be created in Python
390395
# because of unhashability.

0 commit comments

Comments
 (0)