[3.9] bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016) (GH-27028)

This commit is contained in:
Ken Jin 2021-07-06 00:22:43 +08:00 committed by GitHub
parent 9f47d872db
commit 51a29c42f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -0,0 +1,2 @@
Remove uses of :c:func:`PyObject_GC_Del` in error path when initializing
:class:`types.GenericAlias`.

View file

@ -602,7 +602,7 @@ ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
if (!setup_ga(self, origin, arguments)) {
type->tp_free((PyObject *)self);
Py_DECREF(self);
return NULL;
}
return (PyObject *)self;
@ -640,14 +640,14 @@ PyTypeObject Py_GenericAliasType = {
PyObject *
Py_GenericAlias(PyObject *origin, PyObject *args)
{
gaobject *alias = PyObject_GC_New(gaobject, &Py_GenericAliasType);
gaobject *alias = (gaobject*) PyType_GenericAlloc(
(PyTypeObject *)&Py_GenericAliasType, 0);
if (alias == NULL) {
return NULL;
}
if (!setup_ga(alias, origin, args)) {
PyObject_GC_Del((PyObject *)alias);
Py_DECREF(alias);
return NULL;
}
_PyObject_GC_TRACK(alias);
return (PyObject *)alias;
}