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

Miss Islington (bot) webhook-mailer at python.org
Thu Dec 20 03:51:58 EST 2018


https://github.com/python/cpython/commit/3752bc96c0ea1ecf28903cc34cdcd75c658e92ce
commit: 3752bc96c0ea1ecf28903cc34cdcd75c658e92ce
branch: 2.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-12-20T00:51:52-08: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().
(cherry picked from commit d77d97c9a1f593fe161afab97e2a3e2292ab88b9)

Co-authored-by: Zackery Spytz <zspytz at gmail.com>

files:
M Modules/_ctypes/_ctypes.c

diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 9b289af91be7..9aa252d6e265 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -3526,20 +3526,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