Skip to content

[3.12] gh-122332: Fix missing NULL check in asyncio.Task.get_coro (GH-122338) #122345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_asyncio/test_eager_task_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ class DummyLoop:
_, 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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed segfault with :meth:`asyncio.Task.get_coro` when using an eager task
factory.
6 changes: 5 additions & 1 deletion Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading