[3.14] gh-143145: Fix possible reference leak in ctypes _build_result() (GH-143131) (GH-143169)

The result tuple was leaked if __ctypes_from_outparam__() failed for any item.
(cherry picked from commit 579c5b496b)

Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-12-25 18:09:53 +01:00 committed by GitHub
parent 8a61b71eee
commit 88a4d0d34b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 0 deletions

View file

@ -0,0 +1 @@
Fixed a possible reference leak in ctypes when constructing results with multiple output parameters on error.

View file

@ -4551,6 +4551,7 @@ _build_result(PyObject *result, PyObject *callargs,
v = PyTuple_GET_ITEM(callargs, i);
v = PyObject_CallMethodNoArgs(v, &_Py_ID(__ctypes_from_outparam__));
if (v == NULL || numretvals == 1) {
Py_XDECREF(tup);
Py_DECREF(callargs);
return v;
}