summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-12-20 00:51:52 -0800
committerGitHub <noreply@github.com>2018-12-20 00:51:52 -0800
commit3752bc96c0ea1ecf28903cc34cdcd75c658e92ce (patch)
tree6e72ec724b90faa6e45bef8088331968bd72d9e0
parent89b5ea297d67f5efeb8fca0b63fa3d9f7030b2f0 (diff)
downloadcpython-git-3752bc96c0ea1ecf28903cc34cdcd75c658e92ce.tar.gz
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@gmail.com>
-rw-r--r--Modules/_ctypes/_ctypes.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 9b289af91b..9aa252d6e2 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;