[Python-checkins] cpython (3.6): Issue #28408: Fixed a leak and remove redundant code in
serhiy.storchaka
python-checkins at python.org
Tue Oct 25 06:48:18 EDT 2016
https://hg.python.org/cpython/rev/9d618cebfc21
changeset: 104700:9d618cebfc21
branch: 3.6
parent: 104696:c14a2d2a3b19
user: Serhiy Storchaka <storchaka at gmail.com>
date: Tue Oct 25 13:23:56 2016 +0300
summary:
Issue #28408: Fixed a leak and remove redundant code in _PyUnicodeWriter_Finish().
Patch by Xiang Zhang.
files:
Objects/unicodeobject.c | 34 +++++++++++-----------------
1 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -13570,34 +13570,28 @@
_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));
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list