]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-143145: Fix possible reference leak in ctypes _build_result() (GH-143131...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 25 Dec 2025 17:09:53 +0000 (18:09 +0100)
committerGitHub <noreply@github.com>
Thu, 25 Dec 2025 17:09:53 +0000 (19:09 +0200)
The result tuple was leaked if __ctypes_from_outparam__() failed for any item.
(cherry picked from commit 579c5b496b467a2b175cb30caa4f6873cb13c9a1)

Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
Misc/NEWS.d/next/Library/2025-12-24-14-18-52.gh-issue-143145.eXLw8D.rst [new file with mode: 0644]
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 (file)
index 0000000..2aff109
--- /dev/null
@@ -0,0 +1 @@
+Fixed a possible reference leak in ctypes when constructing results with multiple output parameters on error.
index bac119f2ae7a367188e4e8c60ce81a7376cfc3ed..3d48c70bd0d2274b14cc6d41d254f3381c62d1e9 100644 (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;
             }