diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-12-20 00:47:59 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-20 00:47:59 -0800 |
commit | 4b6caaca41def86d80819f1f93c647918e98393f (patch) | |
tree | 46f77d6bcb7f704ccbd5893e47634c7b2fb65e3e /Modules/_ctypes | |
parent | a26201cd8ef17dc81431f768846291c9f4337550 (diff) | |
download | cpython-git-4b6caaca41def86d80819f1f93c647918e98393f.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>
Diffstat (limited to 'Modules/_ctypes')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 937375a4ea..f98eabbb37 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -3409,20 +3409,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; |