8000 bpo-43751: Fix anext() bug where it erroneously returned None by sweeneyde · Pull Request #25238 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-43751: Fix anext() bug where it erroneously returned None #25238

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 16 commits into from
Apr 11, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Avoid leaking awaitable
  • Loading branch information
sweeneyde committed Apr 11, 2021
commit 857a2b0c605897e284115197263a70a1d57fb031
8000 2 changes: 2 additions & 0 deletions Objects/iterobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ anextawaitable_iternext(anextawaitableobject *obj)
if (Py_TYPE(awaitable)->tp_iternext == NULL) {
PyErr_SetString(PyExc_TypeError,
Copy link
Member
@pablogsal pablogsal Apr 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is leaking awaitable.

"__await__ returned a non-iterable");
Py_DECREF(awaitable);
return NULL;
}
}
PyObject *result = (*Py_TYPE(awaitable)->tp_iternext)(awaitable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to decrement awaitable once you are done with it

Py_DECREF(awaitable);
if (result != NULL) {
return result;
}
Expand Down
0