Skip to content

Commit d77d97c

Browse files
ZackerySpytzserhiy-storchaka
authored andcommitted
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().
1 parent b13a20f commit d77d97c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,20 +3483,23 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
34833483
return NULL;
34843484
}
34853485
#endif
3486-
Py_INCREF(dll); /* for KeepRef */
3487-
Py_DECREF(ftuple);
3488-
if (!_validate_paramflags(type, paramflags))
3486+
if (!_validate_paramflags(type, paramflags)) {
3487+
Py_DECREF(ftuple);
34893488
return NULL;
3489+
}
34903490

34913491
self = (PyCFuncPtrObject *)GenericPyCData_new(type, args, kwds);
3492-
if (!self)
3492+
if (!self) {
3493+
Py_DECREF(ftuple);
34933494
return NULL;
3495+
}
34943496

34953497
Py_XINCREF(paramflags);
34963498
self->paramflags = paramflags;
34973499

34983500
*(void **)self->b_ptr = address;
3499-
3501+
Py_INCREF(dll);
3502+
Py_DECREF(ftuple);
35003503
if (-1 == KeepRef((CDataObject *)self, 0, dll)) {
35013504
Py_DECREF((PyObject *)self);
35023505
return NULL;

0 commit comments

Comments
 (0)