Skip to content

Commit cd82efd

Browse files
committed
[3.15] gh-159739: Preserve the normalization buffer on allocation failure (GH-159755)
Save the original buffer before calling PyMem_Resize(), which overwrites its first argument even on failure. (cherry picked from commit c38d75c)
1 parent 9653bdd commit cd82efd

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
@@ -762,9 +762,8 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
762762
}
763763

764764
if (run_length > sortbuflen) {
765-
Py_UCS4 *new_sortbuf = PyMem_Resize(sortbuf,
766-
Py_UCS4,
767-
run_length);
765+
Py_UCS4 *new_sortbuf = sortbuf;
766+
PyMem_Resize(new_sortbuf, Py_UCS4, run_length);
768767
if (new_sortbuf == NULL) {
769768
PyErr_NoMemory();
770769
PyMem_Free(sortbuf);

0 commit comments

Comments
 (0)