gh-143145: Fix possible reference leak in ctypes _build_result() (GH-143131)

The result tuple was leaked if __ctypes_from_outparam__() failed for any item.

Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
This commit is contained in:
Yongtao Huang 2025-12-25 22:24:25 +08:00 committed by GitHub
parent 8d46f961c3
commit 579c5b496b
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

@ -4557,6 +4557,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;
}