mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
bpo-46025: Fix a crash in the atexit module for auto-unregistering functions (GH-30002)
This commit is contained in:
parent
af6b406885
commit
f0d290d25c
3 changed files with 21 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue