From a0eafb0f50efc05a6d6d32f6c95579978936c2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=9F=D0=BE=D0=BF=D0=BE=D0=B2?= Date: Mon, 13 Apr 2026 18:52:43 +0300 Subject: [PATCH 1/4] Fix typo: encodings -> encoding in FileType docs --- Doc/library/argparse.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 8ba11b7d12d552..0091bf95f0cef0 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1970,7 +1970,7 @@ FileType objects run and then use the :keyword:`with`-statement to manage the files. .. versionchanged:: 3.4 - Added the *encodings* and *errors* parameters. + Added the *encoding* and *errors* parameters. .. deprecated:: 3.14 From c07b8582d22ff43475e876f839f7f5b0dda91a5c Mon Sep 17 00:00:00 2001 From: Gleb Popov Date: Mon, 13 Apr 2026 23:08:49 +0300 Subject: [PATCH 2/4] Fix memory leak of iterator in array.array constructor --- Modules/arraymodule.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index a86a7561271b87..3f4f029ef8962c 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -3063,11 +3063,13 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySequence_GetItem(initial, i); if (v == NULL) { Py_DECREF(a); + Py_XDECREF(it); return NULL; } if (setarrayitem(a, i, v) != 0) { Py_DECREF(v); Py_DECREF(a); + Py_XDECREF(it); return NULL; } Py_DECREF(v); From 19395c35a176b50b64fab46683a3915af595d5c6 Mon Sep 17 00:00:00 2001 From: Gleb Popov Date: Tue, 14 Apr 2026 11:32:50 +0300 Subject: [PATCH 3/4] gh-148484: Fix iterator leak in array.array constructor --- Modules/arraymodule.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 3f4f029ef8962c..dfe0e4addec2d4 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -3053,14 +3053,15 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) len = 0; a = newarrayobject(type, len, descr); - if (a == NULL) + if (a == NULL) { + Py_XDECREF(it); return NULL; + } if (len > 0 && !array_Check(initial, state)) { Py_ssize_t i; for (i = 0; i < len; i++) { - PyObject *v = - PySequence_GetItem(initial, i); + PyObject *v = PySequence_GetItem(initial, i); if (v == NULL) { Py_DECREF(a); Py_XDECREF(it); @@ -3081,6 +3082,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) v = array_array_frombytes((PyObject *)a, initial); if (v == NULL) { Py_DECREF(a); + Py_XDECREF(it); return NULL; } Py_DECREF(v); @@ -3091,6 +3093,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) wchar_t *ustr = PyUnicode_AsWideCharString(initial, &n); if (ustr == NULL) { Py_DECREF(a); + Py_XDECREF(it); return NULL; } @@ -3111,6 +3114,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) Py_UCS4 *ustr = PyUnicode_AsUCS4Copy(initial); if (ustr == NULL) { Py_DECREF(a); + Py_XDECREF(it); return NULL; } @@ -3138,6 +3142,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return a; } } + Py_XDECREF(it); PyErr_SetString(PyExc_ValueError, "bad typecode (must be b, B, u, w, h, H, i, I, l, L, q, Q, f or d)"); return NULL; From 1d8058faad08cd0ffda560403ea03dd7b74b4059 Mon Sep 17 00:00:00 2001 From: Gleb Popov Date: Tue, 14 Apr 2026 11:39:32 +0300 Subject: [PATCH 4/4] revert unrelated changes --- Modules/arraymodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index dfe0e4addec2d4..b01e92eb8873ba 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -3061,7 +3061,8 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (len > 0 && !array_Check(initial, state)) { Py_ssize_t i; for (i = 0; i < len; i++) { - PyObject *v = PySequence_GetItem(initial, i); + PyObject *v = + PySequence_GetItem(initial, i); if (v == NULL) { Py_DECREF(a); Py_XDECREF(it);