]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-148653: Fix reference leaks in test_marshal introduced in gh-148698 (GH-148725)
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 18 Apr 2026 12:11:14 +0000 (15:11 +0300)
committerGitHub <noreply@github.com>
Sat, 18 Apr 2026 12:11:14 +0000 (12:11 +0000)
Lib/test/test_marshal.py

index 9ec37d27dfa39f817a92b035f7e2fd7f8eee956a..9c4d91c456dc5d9cf24ecb90a0d6e7c1b3dabb82 100644 (file)
@@ -357,6 +357,9 @@ class BugsTestCase(unittest.TestCase):
         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)
@@ -410,10 +413,12 @@ class BugsTestCase(unittest.TestCase):
         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.