Skip to content

Commit dad8d9b

Browse files
committed
Fix reference leak in ctypes _build_result()
In _ctypes._build_result(), a result tuple is allocated when numretvals > 1. If v becomes NULL during result construction, the function returns early without DECREF'ing the tuple, leaking a reference. Add Py_XDECREF(tup) before returning when numretvals > 1 and v == NULL. Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
1 parent 50ecd6b commit dad8d9b

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4557,6 +4557,7 @@ _build_result(PyObject *result, PyObject *callargs,
45574557
v = PyTuple_GET_ITEM(callargs, i);
45584558
v = PyObject_CallMethodNoArgs(v, &_Py_ID(__ctypes_from_outparam__));
45594559
if (v == NULL || numretvals == 1) {
4560+
Py_XDECREF(tup);
45604561
Py_DECREF(callargs);
45614562
return v;
45624563
}

0 commit comments

Comments
 (0)