https://github.com/python/cpython/commit/7836ecc5daf541061de2072070f7371d41b009ee
commit: 7836ecc5daf541061de2072070f7371d41b009ee
branch: main
author: Thomas Kowalski <[email protected]>
committer: encukou <[email protected]>
date: 2026-03-12T14:27:07+01:00
summary:
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.
files:
M Objects/listobject.c
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 1fcedd3a28c91b..1cc62764e2fd8c 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;
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]