]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-145681: do not deallocate list buffer in `_PyList_AsTupleAndClear` (GH-145680)
authorThomas Kowalski <thom.kowa@gmail.com>
Thu, 12 Mar 2026 13:27:07 +0000 (14:27 +0100)
committerGitHub <noreply@github.com>
Thu, 12 Mar 2026 13:27:07 +0000 (14:27 +0100)
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.

Objects/listobject.c

index 1fcedd3a28c91b4964c891f15a70e8142a047df9..1cc62764e2fd8c3fdfe87311e5e724aef52d77f1 100644 (file)
@@ -3283,10 +3283,8 @@ _PyList_AsTupleAndClear(PyListObject *self)
     Py_BEGIN_CRITICAL_SECTION(self);
     PyObject **items = self->ob_item;
     Py_ssize_t size = Py_SIZE(self);
-    self->ob_item = NULL;
     Py_SET_SIZE(self, 0);
     ret = _PyTuple_FromArraySteal(items, size);
-    free_list_items(items, false);
     Py_END_CRITICAL_SECTION();
     return ret;
 }