Commit d77d97c9 authored by Zackery Spytz's avatar Zackery Spytz Committed by Serhiy Storchaka

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().
parent b13a20f5
...@@ -3483,20 +3483,23 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -3483,20 +3483,23 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL; return NULL;
} }
#endif #endif
Py_INCREF(dll); /* for KeepRef */ if (!_validate_paramflags(type, paramflags)) {
Py_DECREF(ftuple); Py_DECREF(ftuple);
if (!_validate_paramflags(type, paramflags))
return NULL; return NULL;
}
self = (PyCFuncPtrObject *)GenericPyCData_new(type, args, kwds); self = (PyCFuncPtrObject *)GenericPyCData_new(type, args, kwds);
if (!self) if (!self) {
Py_DECREF(ftuple);
return NULL; return NULL;
}
Py_XINCREF(paramflags); Py_XINCREF(paramflags);
self->paramflags = paramflags; self->paramflags = paramflags;
*(void **)self->b_ptr = address; *(void **)self->b_ptr = address;
Py_INCREF(dll);
Py_DECREF(ftuple);
if (-1 == KeepRef((CDataObject *)self, 0, dll)) { if (-1 == KeepRef((CDataObject *)self, 0, dll)) {
Py_DECREF((PyObject *)self); Py_DECREF((PyObject *)self);
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment