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 1010#include "pycore_global_objects.h" // _Py_GET_GLOBAL_OBJECT()
1111#include "pycore_initconfig.h" // _PyStatus_OK()
1212#include "pycore_long.h" // _PyLong_DigitValue
13+ #include "pycore_list.h" // _PyList_GetItemRef
1314#include "pycore_object.h" // _PyObject_GC_TRACK
1415#include "pycore_pymem.h" // PYMEM_CLEANBYTE
1516#include "pycore_strhex.h" // _Py_strhex_with_sep()
@@ -2877,8 +2878,10 @@ _PyBytes_FromList(PyObject *x)
28772878 size = writer .allocated ;
28782879
28792880 for (i = 0 ; i < PyList_GET_SIZE (x ); i ++ ) {
2880- item = PyList_GET_ITEM (x , i );
2881- Py_INCREF (item );
2881+ PyObject * item = _PyList_GetItemRef ((PyListObject * )x , i );
2882+ if (item == NULL ) {
2883+ goto error ;
2884+ }
28822885 value = PyNumber_AsSsize_t (item , NULL );
28832886 Py_DECREF (item );
28842887 if (value == -1 && PyErr_Occurred ())
You can’t perform that action at this time.
0 commit comments