From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sun, 4 Jul 2021 17:55:43 +0000 (-0700) Subject: bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias ... X-Git-Tag: v3.9.7~177 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4684a34c8d2a2ffac7b779edb4ba57f043783478;p=thirdparty%2FPython%2Fcpython.git bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016) (GH-27018) (cherry picked from commit d33943a6c368c2184e238019c63ac7a267da5594) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> --- 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 000000000000..2fc65bcfdeef --- /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 945d20593c7c..bb5fa095d357 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; @@ -644,10 +644,10 @@ Py_GenericAlias(PyObject *origin, PyObject *args) if (alias == NULL) { return NULL; } + _PyObject_GC_TRACK(alias); if (!setup_ga(alias, origin, args)) { - PyObject_GC_Del((PyObject *)alias); + Py_DECREF(alias); return NULL; } - _PyObject_GC_TRACK(alias); return (PyObject *)alias; }