Skip to content

Commit 68330b6

Browse files
bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016)
(cherry picked from commit d33943a) Co-authored-by: Ken Jin <[email protected]>
1 parent 9bf7c2d commit 68330b6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
603603
return NULL;
604604
}
605605
if (!setup_ga(self, origin, arguments)) {
606-
type->tp_free((PyObject *)self);
606+
Py_DECREF(self);
607607
return NULL;
608608
}
609609
return (PyObject *)self;
@@ -650,10 +650,10 @@ Py_GenericAlias(PyObject *origin, PyObject *args)
650650
if (alias == NULL) {
651651
return NULL;
652652
}
653+
_PyObject_GC_TRACK(alias);
653654
if (!setup_ga(alias, origin, args)) {
654-
PyObject_GC_Del((PyObject *)alias);
655+
Py_DECREF(alias);
655656
return NULL;
656657
}
657-
_PyObject_GC_TRACK(alias);
658658
return (PyObject *)alias;
659659
}

0 commit comments

Comments
 (0)