[Python-checkins] bpo-16575: Fix refleak on passing unions in ctypes (GH-17064)

Vinay Sajip webhook-mailer at python.org
Wed Nov 6 10:40:14 EST 2019


https://github.com/python/cpython/commit/484edbf9bf1a9e6bae0fcb10a0c165b89ea79295
commit: 484edbf9bf1a9e6bae0fcb10a0c165b89ea79295
branch: 3.7
author: Ammar Askar <ammar at ammaraskar.com>
committer: Vinay Sajip <vinay_sajip at yahoo.co.uk>
date: 2019-11-06T15:40:06Z
summary:

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.

files:
M Modules/_ctypes/_ctypes.c

diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index d2ce1b074348d..0e209c33a80af 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 "



More information about the Python-checkins mailing list