]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35529: Fix a reference counting bug in PyCFuncPtr_FromDll(). (GH-11229)
authorZackery Spytz <zspytz@gmail.com>
Thu, 20 Dec 2018 08:29:38 +0000 (01:29 -0700)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 20 Dec 2018 08:29:38 +0000 (10:29 +0200)
"dll" would leak if an error occurred in _validate_paramflags() or
GenericPyCData_new().

Modules/_ctypes/_ctypes.c

index 637be4222d98842a9b9c0c676c054fbe6d496816..cc4aab7389b1e7b0221dce3d596f44b254ba4727 100644 (file)
@@ -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;