From d52f22e6f2001e2a66e2eabe587c55d5fbdb74c9 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Sat, 25 Jan 2025 02:14:04 +0000 Subject: [PATCH 1/2] gh-129271: Fix reference leak with unicode writer in fast path in the json module --- Modules/_json.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/_json.c b/Modules/_json.c index 091bcbfdced42b..5497d179e7eb1f 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -413,6 +413,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next if (c == '"') { // Fast path for simple case. if (_PyUnicodeWriter_IsEmpty(writer)) { + PyUnicodeWriter_Discard(writer); PyObject *ret = PyUnicode_Substring(pystr, end, next); if (ret == NULL) { goto bail; From e42dff2cc1d271089d5f56c5a34593d767a51539 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Sat, 25 Jan 2025 15:28:23 +0000 Subject: [PATCH 2/2] fixup! gh-129271: Fix reference leak with unicode writer in fast path in the json module --- Modules/_json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_json.c b/Modules/_json.c index 5497d179e7eb1f..31a5e935e13ad9 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -413,11 +413,11 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next if (c == '"') { // Fast path for simple case. if (_PyUnicodeWriter_IsEmpty(writer)) { - PyUnicodeWriter_Discard(writer); PyObject *ret = PyUnicode_Substring(pystr, end, next); if (ret == NULL) { goto bail; } + PyUnicodeWriter_Discard(writer); *next_end_ptr = next + 1;; return ret; }