]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-143145: Fix possible reference leak in ctypes _build_result() (GH-143131)
authorYongtao Huang <yongtaoh2022@gmail.com>
Thu, 25 Dec 2025 14:24:25 +0000 (22:24 +0800)
committerGitHub <noreply@github.com>
Thu, 25 Dec 2025 14:24:25 +0000 (14:24 +0000)
The result tuple was leaked if __ctypes_from_outparam__() failed for any item.

Signed-off-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 774ac71ce9ec5632658580d2a2b4ca67925c88fe..563e95a762599bb7bb913e71d64e6e0fdcf8099d 100644 (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;
             }