Skip to content

Commit

Permalink
bpo-35529: Fix a reference counting bug in PyCFuncPtr_FromDll(). (pyt…
Browse files Browse the repository at this point in the history
…honGH-11229)

"dll" would leak if an error occurred in _validate_paramflags() or
GenericPyCData_new().
  • Loading branch information
ZackerySpytz authored and serhiy-storchaka committed Dec 20, 2018
1 parent b13a20f commit d77d97c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d77d97c

Please sign in to comment.