[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 c38d75ce32)
This commit is contained in:
Jelle Zijlstra authored and GitHub committed 2026-10-20 19:29:28 +00:00
1 parent 20c33c1a66
commit 4147bccdf2
2 files changed
+3 -3

No files matched your search

@@ -0,0 +1 @@
Fix a memory leak when Unicode normalization cannot grow its temporary buffer.
+2 -3
View File
@@ -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);