Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash in the :term:`free-threaded build` where :c:func:`PyList_New` could leave
a newly allocated list's item buffer pointer uninitialized when the backing
array allocation failed under low memory, leading to an invalid free.
11 changes: 5 additions & 6 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,11 @@ PyList_New(Py_ssize_t size)
return NULL;
}
}
if (size <= 0) {
op->ob_item = NULL;
}
else {
op->ob_item = NULL;
Py_SET_SIZE(op, size);
op->allocated = size;

if (size > 0) {
#ifdef Py_GIL_DISABLED
_PyListArray *array = list_allocate_array(size);
if (array == NULL) {
Expand All @@ -272,8 +273,6 @@ PyList_New(Py_ssize_t size)
return PyErr_NoMemory();
}
}
Py_SET_SIZE(op, size);
op->allocated = size;
_PyObject_GC_TRACK(op);
return (PyObject *) op;
}
Expand Down
Loading