[Python-checkins] [3.9] bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016) (GH-27028)

pablogsal webhook-mailer at python.org
Mon Jul 5 12:22:51 EDT 2021


https://github.com/python/cpython/commit/51a29c42f10bd9368db9a21f2f63319be2e30b95
commit: 51a29c42f10bd9368db9a21f2f63319be2e30b95
branch: 3.9
author: Ken Jin <28750310+Fidget-Spinner at users.noreply.github.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-07-05T17:22:43+01:00
summary:

[3.9] bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016) (GH-27028)

files:
A Misc/NEWS.d/next/Core and Builtins/2021-07-04-23-38-51.bpo-44562.QdeRQo.rst
M Objects/genericaliasobject.c

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 00000000000000..2fc65bcfdeef43
--- /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 945d20593c7c90..69ad8a6d8353a7 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;
 }



More information about the Python-checkins mailing list