From 0c158a3d70676633aa7cfaa29b241292576bb14d Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Sun, 24 Mar 2019 21:34:00 -0600 Subject: [PATCH] bpo-36421: Fix a possible double decref in _ctypes.c's PyCArrayType_new() 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. --- .../Core and Builtins/2019-03-24-21-33-22.bpo-36421.gJ2Pv9.rst | 1 + Modules/_ctypes/_ctypes.c | 1 + 2 files changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-03-24-21-33-22.bpo-36421.gJ2Pv9.rst 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 000000000000000..2577511de2e2d85 --- /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 0d95d2b6f76eceb..45102f3304ec6a5 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;