From 51a29c42f10bd9368db9a21f2f63319be2e30b95 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Tue, 6 Jul 2021 00:22:43 +0800 Subject: [PATCH] =?UTF-8?q?[3.9]=20bpo-44562:=20Remove=20invalid=20PyObjec?= =?UTF-8?q?t=5FGC=5FDel=20from=20error=20path=20of=20types.GenericAlias=20?= =?UTF-8?q?=E2=80=A6=20(GH-27016)=20(GH-27028)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2021-07-04-23-38-51.bpo-44562.QdeRQo.rst | 2 ++ Objects/genericaliasobject.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-07-04-23-38-51.bpo-44562.QdeRQo.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-07-04-23-38-51.bpo-44562.QdeRQo.rst b/Misc/NEWS.d/next/Core and Builtins/2021-07-04-23-38-51.bpo-44562.QdeRQo.rst new file mode 100644 index 00000000000..2fc65bcfdee --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-07-04-23-38-51.bpo-44562.QdeRQo.rst @@ -0,0 +1,2 @@ +Remove uses of :c:func:`PyObject_GC_Del` in error path when initializing +:class:`types.GenericAlias`. diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index 945d20593c7..69ad8a6d835 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -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; }