mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
bpo-34784: Implement correct cleanup in PyStructSequence new implementation (GH-10536)
PyTuple_Pack can fail and return NULL. If this happens, then PyType_FromSpecWithBases will incorrectly create a new type without bases. Also, it will crash on the Py_DECREF that follows. Also free members and type in error conditions.
This commit is contained in:
parent
4c596d54aa
commit
bfb855bef6
1 changed files with 5 additions and 0 deletions
|
|
@ -447,6 +447,10 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc)
|
|||
spec.slots = slots;
|
||||
|
||||
bases = PyTuple_Pack(1, &PyTuple_Type);
|
||||
if (bases == NULL) {
|
||||
PyMem_FREE(members);
|
||||
return NULL;
|
||||
}
|
||||
type = (PyTypeObject *)PyType_FromSpecWithBases(&spec, bases);
|
||||
Py_DECREF(bases);
|
||||
PyMem_FREE(members);
|
||||
|
|
@ -456,6 +460,7 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc)
|
|||
|
||||
if (initialize_structseq_dict(
|
||||
desc, type->tp_dict, n_members, n_unnamed_members) < 0) {
|
||||
Py_DECREF(type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue