Skip to content

Commit 6ff08d9

Browse files
committed
Fixed OOM-0004 from gh-151763
1 parent c08c89a commit 6ff08d9

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a crash in the free-threaded build where :c:func:`PyList_New` could leave
2+
a newly allocated list's item buffer pointer uninitialized when the backing
3+
array allocation failed under low memory, leading to an invalid free.

Objects/listobject.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,11 @@ PyList_New(Py_ssize_t size)
252252
return NULL;
253253
}
254254
}
255-
if (size <= 0) {
256-
op->ob_item = NULL;
257-
}
258-
else {
255+
op->ob_item = NULL;
256+
Py_SET_SIZE(op, 0);
257+
op->allocated = 0;
258+
259+
if (size > 0) {
259260
#ifdef Py_GIL_DISABLED
260261
_PyListArray *array = list_allocate_array(size);
261262
if (array == NULL) {

0 commit comments

Comments
 (0)