diff options
| author | Peter Bierma <zintensitydev@gmail.com> | 2024-08-09 14:06:36 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-09 14:06:36 (GMT) |
| commit | e8fb088dbaa71dd5f0146b2f4a8f7ecbe2ce9625 (patch) | |
| tree | f6cc58c122ff742020e9242be9ae0b074b735ff9 | |
| parent | 60c44ed9756a678411fe738d3141a7fd8930e93c (diff) | |
| download | cpython-e8fb088dbaa71dd5f0146b2f4a8f7ecbe2ce9625.zip cpython-e8fb088dbaa71dd5f0146b2f4a8f7ecbe2ce9625.tar.gz cpython-e8fb088dbaa71dd5f0146b2f4a8f7ecbe2ce9625.tar.bz2 | |
[3.13] gh-122695: Fix double-free when using `gc.get_referents` with a freed `_asyncio.FutureIter` (#122837)
* Backport #122834 for 3.13
| -rw-r--r-- | Lib/test/test_asyncio/test_futures.py | 8 | ||||
| -rw-r--r-- | Misc/NEWS.d/next/Library/2024-08-08-15-05-58.gh-issue-122695.f7pwBv.rst | 2 | ||||
| -rw-r--r-- | Modules/_asynciomodule.c | 11 |
3 files changed, 10 insertions, 11 deletions
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py index 458b704..2417712 100644 --- a/Lib/test/test_asyncio/test_futures.py +++ b/Lib/test/test_asyncio/test_futures.py @@ -675,6 +675,14 @@ class CFutureTests(BaseFutureTests, test_utils.TestCase): with self.assertRaises(AttributeError): del fut._log_traceback + def test_future_iter_get_referents_segfault(self): + # See https://github.com/python/cpython/issues/122695 + import _asyncio + it = iter(self._new_future(loop=self.loop)) + del it + evil = gc.get_referents(_asyncio) + gc.collect() + @unittest.skipUnless(hasattr(futures, '_CFuture'), 'requires the C _asyncio module') diff --git a/Misc/NEWS.d/next/Library/2024-08-08-15-05-58.gh-issue-122695.f7pwBv.rst b/Misc/NEWS.d/next/Library/2024-08-08-15-05-58.gh-issue-122695.f7pwBv.rst new file mode 100644 index 0000000..cc6bc38 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-08-08-15-05-58.gh-issue-122695.f7pwBv.rst @@ -0,0 +1,2 @@ +Fixed double-free when using :func:`gc.get_referents` with a freed +:class:`asyncio.Future` iterator. diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 6e87de5..3babd33 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -3529,17 +3529,6 @@ module_traverse(PyObject *mod, visitproc visit, void *arg) Py_VISIT(state->iscoroutine_typecache); Py_VISIT(state->context_kwname); - -#ifndef Py_GIL_DISABLED - // Visit freelist. - PyObject *next = (PyObject*) state->fi_freelist; - while (next != NULL) { - PyObject *current = next; - Py_VISIT(current); - next = (PyObject*) ((futureiterobject*) current)->future; - } -#endif - return 0; } |
