From 484edbf9bf1a9e6bae0fcb10a0c165b89ea79295 Mon Sep 17 00:00:00 2001 From: Ammar Askar Date: Wed, 6 Nov 2019 10:40:06 -0500 Subject: [PATCH] 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. --- Modules/_ctypes/_ctypes.c | 1 + 1 file changed, 1 insertion(+) 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 " -- 2.47.3