mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
gh-129732: Fix race on shared->array
in qsbr code under free-threading (gh-129738)
The read of `shared->array` should happen under the lock to avoid a race.
This commit is contained in:
parent
78377c788e
commit
b4ff8b22b3
2 changed files with 7 additions and 6 deletions
|
@ -205,15 +205,15 @@ _Py_qsbr_reserve(PyInterpreterState *interp)
|
|||
}
|
||||
_PyEval_StartTheWorld(interp);
|
||||
}
|
||||
PyMutex_Unlock(&shared->mutex);
|
||||
|
||||
if (qsbr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Return an index rather than the pointer because the array may be
|
||||
// resized and the pointer invalidated.
|
||||
return (struct _qsbr_pad *)qsbr - shared->array;
|
||||
Py_ssize_t index = -1;
|
||||
if (qsbr != NULL) {
|
||||
index = (struct _qsbr_pad *)qsbr - shared->array;
|
||||
}
|
||||
PyMutex_Unlock(&shared->mutex);
|
||||
return index;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue