[Python-checkins] bpo-35529: Fix a reference counting bug in PyCFuncPtr_FromDll(). (GH-11229)

Serhiy Storchaka webhook-mailer at python.org
Thu Dec 20 03:29:46 EST 2018


https://github.com/python/cpython/commit/d77d97c9a1f593fe161afab97e2a3e2292ab88b9
commit: d77d97c9a1f593fe161afab97e2a3e2292ab88b9
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2018-12-20T10:29:38+02:00
summary:

bpo-35529: Fix a reference counting bug in PyCFuncPtr_FromDll(). (GH-11229)

"dll" would leak if an error occurred in _validate_paramflags() or
GenericPyCData_new().

files:
M Modules/_ctypes/_ctypes.c

diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 637be4222d98..cc4aab7389b1 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -3483,20 +3483,23 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
         return NULL;
     }
 #endif
-    Py_INCREF(dll); /* for KeepRef */
-    Py_DECREF(ftuple);
-    if (!_validate_paramflags(type, paramflags))
+    if (!_validate_paramflags(type, paramflags)) {
+        Py_DECREF(ftuple);
         return NULL;
+    }
 
     self = (PyCFuncPtrObject *)GenericPyCData_new(type, args, kwds);
-    if (!self)
+    if (!self) {
+        Py_DECREF(ftuple);
         return NULL;
+    }
 
     Py_XINCREF(paramflags);
     self->paramflags = paramflags;
 
     *(void **)self->b_ptr = address;
-
+    Py_INCREF(dll);
+    Py_DECREF(ftuple);
     if (-1 == KeepRef((CDataObject *)self, 0, dll)) {
         Py_DECREF((PyObject *)self);
         return NULL;



More information about the Python-checkins mailing list