summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2019-03-25 02:07:47 -0600
committerSerhiy Storchaka <storchaka@gmail.com>2019-03-25 10:07:47 +0200
commit5e333784f007950f22de44c1ffab5b0c03d6691f (patch)
tree1b331b21914777b6d2a75980fa9fd7b00800f150
parentdd5417afcf8924bcdd7077351941ad21727ef644 (diff)
downloadcpython-git-5e333784f007950f22de44c1ffab5b0c03d6691f.tar.gz
bpo-36421: Fix a possible double decref in _ctypes.c's PyCArrayType_new(). (GH-12530)
Set type_attr to NULL after the assignment to stgdict->proto (like what is done with stgdict after the Py_SETREF() call) so that it is not decrefed twice on error.
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2019-03-24-21-33-22.bpo-36421.gJ2Pv9.rst1
-rw-r--r--Modules/_ctypes/_ctypes.c1
2 files changed, 2 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-03-24-21-33-22.bpo-36421.gJ2Pv9.rst b/Misc/NEWS.d/next/Core and Builtins/2019-03-24-21-33-22.bpo-36421.gJ2Pv9.rst
new file mode 100644
index 0000000000..2577511de2
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-03-24-21-33-22.bpo-36421.gJ2Pv9.rst
@@ -0,0 +1 @@
+Fix a possible double decref in _ctypes.c's ``PyCArrayType_new()``.
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 0d95d2b6f7..45102f3304 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -1522,6 +1522,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
stgdict->align = itemalign;
stgdict->length = length;
stgdict->proto = type_attr;
+ type_attr = NULL;
stgdict->paramfunc = &PyCArrayType_paramfunc;