mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Issue #16971: Fix a refleak in the charmap decoder.
This commit is contained in:
commit
2aee6a6460
1 changed files with 12 additions and 4 deletions
|
@ -7383,27 +7383,35 @@ Error:
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1)
|
if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) {
|
||||||
|
Py_DECREF(x);
|
||||||
goto onError;
|
goto onError;
|
||||||
|
}
|
||||||
PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value);
|
PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value);
|
||||||
writer.pos++;
|
writer.pos++;
|
||||||
}
|
}
|
||||||
else if (PyUnicode_Check(x)) {
|
else if (PyUnicode_Check(x)) {
|
||||||
if (PyUnicode_READY(x) == -1)
|
if (PyUnicode_READY(x) == -1) {
|
||||||
|
Py_DECREF(x);
|
||||||
goto onError;
|
goto onError;
|
||||||
|
}
|
||||||
if (PyUnicode_GET_LENGTH(x) == 1) {
|
if (PyUnicode_GET_LENGTH(x) == 1) {
|
||||||
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 (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1)
|
if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) {
|
||||||
|
Py_DECREF(x);
|
||||||
goto onError;
|
goto onError;
|
||||||
|
}
|
||||||
PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value);
|
PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value);
|
||||||
writer.pos++;
|
writer.pos++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
writer.overallocate = 1;
|
writer.overallocate = 1;
|
||||||
if (_PyUnicodeWriter_WriteStr(&writer, x) == -1)
|
if (_PyUnicodeWriter_WriteStr(&writer, x) == -1) {
|
||||||
|
Py_DECREF(x);
|
||||||
goto onError;
|
goto onError;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue