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()
@@ -2866,7 +2867,6 @@ _PyBytes_FromList(PyObject *x)
28662867 Py_ssize_t i , size = PyList_GET_SIZE (x );
28672868 Py_ssize_t value ;
28682869 char * str ;
2869- PyObject * item ;
28702870 _PyBytesWriter writer ;
28712871
28722872 _PyBytesWriter_Init (& writer );
@@ -2877,8 +2877,10 @@ _PyBytes_FromList(PyObject *x)
28772877 size = writer .allocated ;
28782878
28792879 for (i = 0 ; i < PyList_GET_SIZE (x ); i ++ ) {
2880- item = PyList_GET_ITEM (x , i );
2881- Py_INCREF (item );
2880+ PyObject * item = _PyList_GetItemRef ((PyListObject * )x , i );
2881+ if (item == NULL ) {
2882+ goto error ;
2883+ }
28822884 value = PyNumber_AsSsize_t (item , NULL );
28832885 Py_DECREF (item );
28842886 if (value == -1 && PyErr_Occurred ())
You can’t perform that action at this time.
0 commit comments