summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-25 10:25:04 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-25 10:25:04 (GMT)
commita4f882306394488c06f0412369d52b25e516a0c6 (patch)
tree220c91eae50f9d35cd20fc1ab5ebe5a8e60c33cb /Objects/unicodeobject.c
parent8416196197187c7fd59b20eed890d5235d6fa3d3 (diff)
parentc8bc3d1c07e120ce4c887d618f9934e961453b3d (diff)
downloadcpython-a4f882306394488c06f0412369d52b25e516a0c6.zip
cpython-a4f882306394488c06f0412369d52b25e516a0c6.tar.gz
cpython-a4f882306394488c06f0412369d52b25e516a0c6.tar.bz2
Issue #28408: Fixed a leak and remove redundant code in _PyUnicodeWriter_Finish().
Patch by Xiang Zhang.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 75c5e86..2a0dc76 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -13551,34 +13551,28 @@ PyObject *
_PyUnicodeWriter_Finish(_PyUnicodeWriter *writer)
{
PyObject *str;
+
if (writer->pos == 0) {
Py_CLEAR(writer->buffer);
_Py_RETURN_UNICODE_EMPTY();
}
+
+ str = writer->buffer;
+ writer->buffer = NULL;
+
if (writer->readonly) {
- str = writer->buffer;
- writer->buffer = NULL;
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)
- return NULL;
- str = str2;
+ if (PyUnicode_GET_LENGTH(str) != writer->pos) {
+ PyObject *str2;
+ str2 = resize_compact(str, writer->pos);
+ if (str2 == NULL) {
+ Py_DECREF(str);
+ return NULL;
}
+ str = str2;
}
assert(_PyUnicode_CheckConsistency(str, 1));