Skip to content

Commit 4147bcc

Browse files
authored
[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 c38d75c)
1 parent 20c33c1 commit 4147bcc

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a memory leak when Unicode normalization cannot grow its temporary buffer.

‎Modules/unicodedata.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,8 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
716716
}
717717

718718
if (run_length > sortbuflen) {
719-
Py_UCS4 *new_sortbuf = PyMem_Resize(sortbuf,
720-
Py_UCS4,
721-
run_length);
719+
Py_UCS4 *new_sortbuf = sortbuf;
720+
PyMem_Resize(new_sortbuf, Py_UCS4, run_length);
722721
if (new_sortbuf == NULL) {
723722
PyErr_NoMemory();
724723
PyMem_Free(sortbuf);

0 commit comments

Comments
 (0)