mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
TSAN fixes
This commit is contained in:
parent
b0adc30759
commit
470b9e4362
3 changed files with 11 additions and 7 deletions
|
|
@ -5441,7 +5441,10 @@ _imp__set_lazy_attributes_impl(PyObject *module, PyObject *child_module,
|
|||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
PyObject *child_dict = NULL;
|
||||
PyObject *ret = NULL;
|
||||
PyObject *lazy_modules = tstate->interp->imports.lazy_modules;
|
||||
// Use atomic load and hold a reference to prevent use-after-free
|
||||
// if another thread clears lazy_modules during interpreter shutdown.
|
||||
PyObject *lazy_modules = FT_ATOMIC_LOAD_PTR_RELAXED(tstate->interp->imports.lazy_modules);
|
||||
Py_XINCREF(lazy_modules);
|
||||
if (lazy_modules != NULL) {
|
||||
PyObject *lazy_submodules = PyDict_GetItemWithError(lazy_modules, name);
|
||||
if (lazy_submodules == NULL) {
|
||||
|
|
@ -5483,6 +5486,7 @@ _imp__set_lazy_attributes_impl(PyObject *module, PyObject *child_module,
|
|||
ret = Py_NewRef(Py_None);
|
||||
|
||||
error:
|
||||
Py_XDECREF(lazy_modules);
|
||||
Py_XDECREF(child_dict);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue