diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-12-09 13:53:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-09 13:53:44 (GMT) |
commit | f0d290d25cad66e615ada68ba190b8a23ac1deaa (patch) | |
tree | 3a95b2b47cd9b56b49e0a3ef4645db3e4b6087a3 /Modules/atexitmodule.c | |
parent | af6b4068859a5d0c8afd696f3c0c0155660211a4 (diff) | |
download | cpython-f0d290d25cad66e615ada68ba190b8a23ac1deaa.zip cpython-f0d290d25cad66e615ada68ba190b8a23ac1deaa.tar.gz cpython-f0d290d25cad66e615ada68ba190b8a23ac1deaa.tar.bz2 |
bpo-46025: Fix a crash in the atexit module for auto-unregistering functions (GH-30002)
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); |