https://github.com/python/cpython/commit/88a4d0d34b7dc67f3daea57898c281439dce085d
commit: 88a4d0d34b7dc67f3daea57898c281439dce085d
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-12-25T19:09:53+02:00
summary:

[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 579c5b496b467a2b175cb30caa4f6873cb13c9a1)

Signed-off-by: Yongtao Huang <[email protected]>
Co-authored-by: Yongtao Huang <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-12-24-14-18-52.gh-issue-143145.eXLw8D.rst
M Modules/_ctypes/_ctypes.c

diff --git 
a/Misc/NEWS.d/next/Library/2025-12-24-14-18-52.gh-issue-143145.eXLw8D.rst 
b/Misc/NEWS.d/next/Library/2025-12-24-14-18-52.gh-issue-143145.eXLw8D.rst
new file mode 100644
index 00000000000000..2aff1090b1812f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-12-24-14-18-52.gh-issue-143145.eXLw8D.rst
@@ -0,0 +1 @@
+Fixed a possible reference leak in ctypes when constructing results with 
multiple output parameters on error.
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index bac119f2ae7a36..3d48c70bd0d227 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -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;
             }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to