mirror of https://github.com/python/cpython
Issue #28408: Fixed a leak and remove redundant code in _PyUnicodeWriter_Finish().
Patch by Xiang Zhang.
This commit is contained in:
commit
a4f8823063
|
@ -13551,34 +13551,28 @@ PyObject *
|
|||
_PyUnicodeWriter_Finish(_PyUnicodeWriter *writer)
|
||||
{
|
||||
PyObject *str;
|
||||
|
||||
if (writer->pos == 0) {
|
||||
Py_CLEAR(writer->buffer);
|
||||
_Py_RETURN_UNICODE_EMPTY();
|
||||
}
|
||||
if (writer->readonly) {
|
||||
|
||||
str = writer->buffer;
|
||||
writer->buffer = NULL;
|
||||
|
||||
if (writer->readonly) {
|
||||
assert(PyUnicode_GET_LENGTH(str) == writer->pos);
|
||||
return str;
|
||||
}
|
||||
if (writer->pos == 0) {
|
||||
Py_CLEAR(writer->buffer);
|
||||
|
||||
/* Get the empty Unicode string singleton ('') */
|
||||
_Py_INCREF_UNICODE_EMPTY();
|
||||
str = unicode_empty;
|
||||
}
|
||||
else {
|
||||
str = writer->buffer;
|
||||
writer->buffer = NULL;
|
||||
|
||||
if (PyUnicode_GET_LENGTH(str) != writer->pos) {
|
||||
PyObject *str2;
|
||||
str2 = resize_compact(str, writer->pos);
|
||||
if (str2 == NULL)
|
||||
if (str2 == NULL) {
|
||||
Py_DECREF(str);
|
||||
return NULL;
|
||||
str = str2;
|
||||
}
|
||||
str = str2;
|
||||
}
|
||||
|
||||
assert(_PyUnicode_CheckConsistency(str, 1));
|
||||
|
|
Loading…
Reference in New Issue