]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-148653: Fix reference leaks in test_marshal introduced in gh-148698 (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 18 Apr 2026 12:35:51 +0000 (14:35 +0200)
committerGitHub <noreply@github.com>
Sat, 18 Apr 2026 12:35:51 +0000 (12:35 +0000)
(cherry picked from commit 7ce737ea11919aebf7eef174f910759e74d0ea50)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_marshal.py

index f6962f1e07053ab5cfee8b341789eaed3289ac15..b67044e66aa331ccdfc3764061e967d847de1f34 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)
@@ -404,10 +407,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.