File tree Expand file tree Collapse file tree
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Fix a race condition in ``_PyBytes_FromList `` in free-threading mode.
Original file line number Diff line number Diff line change 1111#include "pycore_global_objects.h" // _Py_GET_GLOBAL_OBJECT()
1212#include "pycore_initconfig.h" // _PyStatus_OK()
1313#include "pycore_long.h" // _PyLong_DigitValue
14+ #include "pycore_list.h" // _PyList_GetItemRef
1415#include "pycore_object.h" // _PyObject_GC_TRACK
1516#include "pycore_pymem.h" // PYMEM_CLEANBYTE
1617#include "pycore_strhex.h" // _Py_strhex_with_sep()
@@ -2991,8 +2992,10 @@ _PyBytes_FromList(PyObject *x)
29912992 size = _PyBytesWriter_GetAllocated (writer );
29922993
29932994 for (Py_ssize_t i = 0 ; i < PyList_GET_SIZE (x ); i ++ ) {
2994- PyObject * item = PyList_GET_ITEM (x , i );
2995- Py_INCREF (item );
2995+ PyObject * item = _PyList_GetItemRef ((PyListObject * )x , i );
2996+ if (item == NULL ) {
2997+ goto error ;
2998+ }
29962999 Py_ssize_t value = PyNumber_AsSsize_t (item , NULL );
29973000 Py_DECREF (item );
29983001 if (value == -1 && PyErr_Occurred ())
You can’t perform that action at this time.
0 commit comments