Skip to content

Commit 7836ecc

Browse files
gh-145681: do not deallocate list buffer in _PyList_AsTupleAndClear (GH-145680)
Setting the size to 0 turns the list contents into overallocated memory that the deallocator will free. Ownership is transferred to the new tuple so no refcount adjustment is needed.
1 parent 453562a commit 7836ecc

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

Objects/listobject.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,10 +3283,8 @@ _PyList_AsTupleAndClear(PyListObject *self)
32833283
Py_BEGIN_CRITICAL_SECTION(self);
32843284
PyObject **items = self->ob_item;
32853285
Py_ssize_t size = Py_SIZE(self);
3286-
self->ob_item = NULL;
32873286
Py_SET_SIZE(self, 0);
32883287
ret = _PyTuple_FromArraySteal(items, size);
3289-
free_list_items(items, false);
32903288
Py_END_CRITICAL_SECTION();
32913289
return ret;
32923290
}

0 commit comments

Comments
 (0)