Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
I discovered this while working on#126080. If the func is given a context that isn'tNone, instead of doingPy_XSETREF it'll just do a regular assignment meaning that whatever was there before wont have its reference count decreased.
cpython/Modules/_asynciomodule.c
Lines 2122 to 2124 in2544159
| }else { | |
| self->task_context=Py_NewRef(context); | |
| } |
importasyncioimportsys# for convenience so I dont have to set up everything else for a Task obj# and can just focus on the ref leakclassBreak:def__str__(self):raiseException("break")asyncdefcoro():passtask=asyncio.Task.__new__(asyncio.Task)co=coro()obj=object()print("refcount before bug",sys.getrefcount(obj))for_inrange(10000):try:task.__init__(co,context=obj,name=Break())except:passprint("refcount after bug",sys.getrefcount(obj))
Output
refcount before bug 2refcount after bug 10002CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
- gh-126083: Fix a reference leak in
asyncio.Taskwhen reinitializing with new non-Nonecontext #126103 - [3.13] gh-126083: Fix a reference leak in
asyncio.Taskwhen reinitializing with new non-Nonecontext (GH-126103) #126229 - [3.12] gh-126083: Fix a reference leak in
asyncio.Taskwhen reinitializing with new non-Nonecontext (GH-126103) #126230
Metadata
Metadata
Assignees
Labels
Projects
Status
Done