Skip to content

Commit 51a29c4

Browse files
[3.9] bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016) (GH-27028)
1 parent 9f47d87 commit 51a29c4

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove uses of :c:func:`PyObject_GC_Del` in error path when initializing
2+
:class:`types.GenericAlias`.

Objects/genericaliasobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
602602
return NULL;
603603
}
604604
if (!setup_ga(self, origin, arguments)) {
605-
type->tp_free((PyObject *)self);
605+
Py_DECREF(self);
606606
return NULL;
607607
}
608608
return (PyObject *)self;
@@ -640,14 +640,14 @@ PyTypeObject Py_GenericAliasType = {
640640
PyObject *
641641
Py_GenericAlias(PyObject *origin, PyObject *args)
642642
{
643-
gaobject *alias = PyObject_GC_New(gaobject, &Py_GenericAliasType);
643+
gaobject *alias = (gaobject*) PyType_GenericAlloc(
644+
(PyTypeObject *)&Py_GenericAliasType, 0);
644645
if (alias == NULL) {
645646
return NULL;
646647
}
647648
if (!setup_ga(alias, origin, args)) {
648-
PyObject_GC_Del((PyObject *)alias);
649+
Py_DECREF(alias);
649650
return NULL;
650651
}
651-
_PyObject_GC_TRACK(alias);
652652
return (PyObject *)alias;
653653
}

0 commit comments

Comments
 (0)