Skip to content

Commit 4684a34

Browse files
bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016) (GH-27018)
(cherry picked from commit d33943a) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
1 parent 21be6cb commit 4684a34

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

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: 3 additions & 3 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;
@@ -644,10 +644,10 @@ Py_GenericAlias(PyObject *origin, PyObject *args)
644644
if (alias == NULL) {
645645
return NULL;
646646
}
647+
_PyObject_GC_TRACK(alias);
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)