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 60011f2ec84eb3..9bd3639d9c3f41 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -746,7 +746,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);