diff options
Diffstat (limited to 'Modules/atexitmodule.c')
-rw-r--r-- | Modules/atexitmodule.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c index e536b4a..95c653c 100644 --- a/Modules/atexitmodule.c +++ b/Modules/atexitmodule.c @@ -93,13 +93,16 @@ atexit_callfuncs(struct atexit_state *state) continue; } + // bpo-46025: Increment the refcount of cb->func as the call itself may unregister it + PyObject* the_func = Py_NewRef(cb->func); PyObject *res = PyObject_Call(cb->func, cb->args, cb->kwargs); if (res == NULL) { - _PyErr_WriteUnraisableMsg("in atexit callback", cb->func); + _PyErr_WriteUnraisableMsg("in atexit callback", the_func); } else { Py_DECREF(res); } + Py_DECREF(the_func); } atexit_cleanup(state); |