]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-16575: Fix refleak on passing unions in ctypes (GH-17064)
authorAmmar Askar <ammar@ammaraskar.com>
Wed, 6 Nov 2019 15:40:06 +0000 (10:40 -0500)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Wed, 6 Nov 2019 15:40:06 +0000 (15:40 +0000)
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

index d2ce1b074348dcb1ec92437c9f3667b56d03139c..0e209c33a80af9e081512c69613f5e97dbbe0a3e 100644 (file)
@@ -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 "