From: Ammar Askar Date: Wed, 6 Nov 2019 15:40:06 +0000 (-0500) Subject: bpo-16575: Fix refleak on passing unions in ctypes (GH-17064) X-Git-Tag: v3.7.6rc1~64 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=484edbf9bf1a9e6bae0fcb10a0c165b89ea79295;p=thirdparty%2FPython%2Fcpython.git bpo-16575: Fix refleak on passing unions in ctypes (GH-17064) The master and 3.8 versions of the previous change work as expected because we perform the lookup for the `from_param` after the union check. However, in 3.7, this lookup happens before the union validation and so we must decrease the reference for `cnv` before returning. --- diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index d2ce1b074348..0e209c33a80a 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2285,6 +2285,7 @@ converters_from_argtypes(PyObject *ob) if (stgdict->flags & TYPEFLAG_HASUNION) { Py_DECREF(converters); Py_DECREF(ob); + Py_DECREF(cnv); if (!PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, "item %zd in _argtypes_ passes a union by "