Commit afb1cb55 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #16971: Fix a refleak in the charmap decoder.

parent 1e49dde2
...@@ -7510,14 +7510,18 @@ Error: ...@@ -7510,14 +7510,18 @@ Error:
Py_DECREF(x); Py_DECREF(x);
goto onError; goto onError;
} }
if (unicode_putchar(&v, &outpos, value) < 0) if (unicode_putchar(&v, &outpos, value) < 0) {
Py_DECREF(x);
goto onError; goto onError;
}
} }
else if (PyUnicode_Check(x)) { else if (PyUnicode_Check(x)) {
Py_ssize_t targetsize; Py_ssize_t targetsize;
if (PyUnicode_READY(x) == -1) if (PyUnicode_READY(x) == -1) {
Py_DECREF(x);
goto onError; goto onError;
}
targetsize = PyUnicode_GET_LENGTH(x); targetsize = PyUnicode_GET_LENGTH(x);
if (targetsize == 1) { if (targetsize == 1) {
...@@ -7525,8 +7529,10 @@ Error: ...@@ -7525,8 +7529,10 @@ Error:
Py_UCS4 value = PyUnicode_READ_CHAR(x, 0); Py_UCS4 value = PyUnicode_READ_CHAR(x, 0);
if (value == 0xFFFE) if (value == 0xFFFE)
goto Undefined; goto Undefined;
if (unicode_putchar(&v, &outpos, value) < 0) if (unicode_putchar(&v, &outpos, value) < 0) {
Py_DECREF(x);
goto onError; goto onError;
}
} }
else if (targetsize > 1) { else if (targetsize > 1) {
/* 1-n mapping */ /* 1-n mapping */
...@@ -7543,8 +7549,11 @@ Error: ...@@ -7543,8 +7549,11 @@ Error:
goto onError; goto onError;
} }
} }
if (unicode_widen(&v, outpos, PyUnicode_MAX_CHAR_VALUE(x)) < 0) if (unicode_widen(&v, outpos,
PyUnicode_MAX_CHAR_VALUE(x)) < 0) {
Py_DECREF(x);
goto onError; goto onError;
}
PyUnicode_CopyCharacters(v, outpos, x, 0, targetsize); PyUnicode_CopyCharacters(v, outpos, x, 0, targetsize);
outpos += targetsize; outpos += targetsize;
extrachars -= targetsize; extrachars -= targetsize;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment