Commit 4e9da0d1 authored by Eric Snow's avatar Eric Snow Committed by GitHub

bpo-32604: Fix memory leaks in the new _xxsubinterpreters module. (#5507)

parent 2f79c014
...@@ -362,12 +362,14 @@ class DestroyTests(TestBase): ...@@ -362,12 +362,14 @@ class DestroyTests(TestBase):
def test_from_current(self): def test_from_current(self):
main, = interpreters.list_all() main, = interpreters.list_all()
id = interpreters.create() id = interpreters.create()
script = dedent(""" script = dedent(f"""
import _xxsubinterpreters as _interpreters import _xxsubinterpreters as _interpreters
_interpreters.destroy({}) try:
""").format(id) _interpreters.destroy({id})
except RuntimeError:
pass
""")
with self.assertRaises(RuntimeError):
interpreters.run_string(id, script) interpreters.run_string(id, script)
self.assertEqual(set(interpreters.list_all()), {main, id}) self.assertEqual(set(interpreters.list_all()), {main, id})
...@@ -761,12 +763,12 @@ class ChannelIDTests(TestBase): ...@@ -761,12 +763,12 @@ class ChannelIDTests(TestBase):
self.assertEqual(int(cid), 10) self.assertEqual(int(cid), 10)
def test_bad_id(self): def test_bad_id(self):
ids = [-1, 2**64, "spam"] for cid in [-1, 'spam']:
for cid in ids:
with self.subTest(cid): with self.subTest(cid):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
interpreters._channel_id(cid) interpreters._channel_id(cid)
with self.assertRaises(OverflowError):
interpreters._channel_id(2**64)
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
interpreters._channel_id(object()) interpreters._channel_id(object())
......
This diff is collapsed.
...@@ -1242,6 +1242,7 @@ _PyCrossInterpreterData_Lookup(PyObject *obj) ...@@ -1242,6 +1242,7 @@ _PyCrossInterpreterData_Lookup(PyObject *obj)
break; break;
} }
} }
Py_DECREF(cls);
PyThread_release_lock(_PyRuntime.xidregistry.mutex); PyThread_release_lock(_PyRuntime.xidregistry.mutex);
return getdata; return getdata;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment