From 7836ecc5daf541061de2072070f7371d41b009ee Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Thu, 12 Mar 2026 14:27:07 +0100 Subject: [PATCH] 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. --- Objects/listobject.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Objects/listobject.c b/Objects/listobject.c index 1fcedd3a28c9..1cc62764e2fd 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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; } -- 2.47.3