https://github.com/python/cpython/commit/4147bccdf22042071016ff666fa11db30f38fb0e
commit: 4147bccdf22042071016ff666fa11db30f38fb0e
branch: 3.14
author: Jelle Zijlstra <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-10-20T19:29:28Z
summary:
[3.14] gh-159739: Preserve the normalization buffer on allocation failure
(GH-159755) (#159933)
Save the original buffer before calling PyMem_Resize(), which overwrites its
first argument even on failure.
(cherry picked from commit c38d75ce321b72a67a04f41589a2e405ed3145a7)
files:
A Misc/NEWS.d/next/Library/2026-10-19-19-33-35.gh-issue-159739.b5fbca.rst
M Modules/unicodedata.c
diff --git
a/Misc/NEWS.d/next/Library/2026-10-19-19-33-35.gh-issue-159739.b5fbca.rst
b/Misc/NEWS.d/next/Library/2026-10-19-19-33-35.gh-issue-159739.b5fbca.rst
new file mode 100644
index 00000000000000..d4a662b10d9f4f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-10-19-19-33-35.gh-issue-159739.b5fbca.rst
@@ -0,0 +1 @@
+Fix a memory leak when Unicode normalization cannot grow its temporary buffer.
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index d9b477a12b4b47..014990ac60991e 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -716,9 +716,8 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
}
if (run_length > sortbuflen) {
- Py_UCS4 *new_sortbuf = PyMem_Resize(sortbuf,
- Py_UCS4,
- run_length);
+ Py_UCS4 *new_sortbuf = sortbuf;
+ PyMem_Resize(new_sortbuf, Py_UCS4, run_length);
if (new_sortbuf == NULL) {
PyErr_NoMemory();
PyMem_Free(sortbuf);
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]