]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-122332: Fix missing `NULL` check in `asyncio.Task.get_coro` (GH-122338...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 27 Jul 2024 07:06:40 +0000 (09:06 +0200)
committerGitHub <noreply@github.com>
Sat, 27 Jul 2024 07:06:40 +0000 (12:36 +0530)
gh-122332: Fix missing `NULL` check in `asyncio.Task.get_coro` (GH-122338)
(cherry picked from commit c08696286f52d286674f264eecf7b33a335a890b)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Lib/test/test_asyncio/test_eager_task_factory.py
Misc/NEWS.d/next/Library/2024-07-26-21-21-13.gh-issue-122332.fvw88r.rst [new file with mode: 0644]
Modules/_asynciomodule.c

index 346888735ff70ba3e80f0a53b109125c60f728ef..58c06287bc3c5de35df8a3b4a9cc9fb38653c01d 100644 (file)
@@ -246,6 +246,18 @@ class CEagerTaskFactoryLoopTests(EagerTaskFactoryLoopTests, test_utils.TestCase)
         _, out, err = assert_python_ok("-c", code)
         self.assertFalse(err)
 
+    def test_issue122332(self):
+       async def coro():
+           pass
+
+       async def run():
+           task = self.loop.create_task(coro())
+           await task
+           self.assertIsNone(task.get_coro())
+
+       self.run_coro(run())
+
+
 class AsyncTaskCounter:
     def __init__(self, loop, *, task_class, eager):
         self.suspense_count = 0
diff --git a/Misc/NEWS.d/next/Library/2024-07-26-21-21-13.gh-issue-122332.fvw88r.rst b/Misc/NEWS.d/next/Library/2024-07-26-21-21-13.gh-issue-122332.fvw88r.rst
new file mode 100644 (file)
index 0000000..55bb1dc
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed segfault with :meth:`asyncio.Task.get_coro` when using an eager task
+factory.
index 05e79915ba7c282f761bc4ab70ff4f8ef1da987a..6b969edca2980468f537f6dfb1f88df4732d730b 100644 (file)
@@ -2509,7 +2509,11 @@ static PyObject *
 _asyncio_Task_get_coro_impl(TaskObj *self)
 /*[clinic end generated code: output=bcac27c8cc6c8073 input=d2e8606c42a7b403]*/
 {
-    return Py_NewRef(self->task_coro);
+    if (self->task_coro) {
+        return Py_NewRef(self->task_coro);
+    }
+
+    Py_RETURN_NONE;
 }
 
 /*[clinic input]