Skip to content

Commit a3feafd

Browse files
committed
gh-159739: Preserve the normalization buffer on allocation failure
Save the original buffer before calling PyMem_Resize(), which overwrites its first argument even on failure. Backport to 3.15 and 3.14; the affected allocation spans multiple lines on those branches.
1 parent a071788 commit a3feafd

2 files changed

Lines changed: 3 additions & 1 deletion

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
746746
}
747747

748748
if (run_length > sortbuflen) {
749-
Py_UCS4 *new_sortbuf = PyMem_Resize(sortbuf, Py_UCS4, run_length);
749+
Py_UCS4 *new_sortbuf = sortbuf;
750+
PyMem_Resize(new_sortbuf, Py_UCS4, run_length);
750751
if (new_sortbuf == NULL) {
751752
PyErr_NoMemory();
752753
PyMem_Free(sortbuf);

0 commit comments

Comments
 (0)