diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-07-08 22:37:24 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-07-08 22:37:24 (GMT) |
commit | 9e6b4d715c46c0fa518fd76440b59516a9f6f7ea (patch) | |
tree | 6f76d38c22228457234637d73c6b824a8b7beb82 /Objects/unicodeobject.c | |
parent | 79799266165b5d8d4e8b9b007d81ba3b00197ca9 (diff) | |
download | cpython-9e6b4d715c46c0fa518fd76440b59516a9f6f7ea.zip cpython-9e6b4d715c46c0fa518fd76440b59516a9f6f7ea.tar.gz cpython-9e6b4d715c46c0fa518fd76440b59516a9f6f7ea.tar.bz2 |
Issue #18408: _PyUnicodeWriter_Finish() now clears its buffer attribute in all
cases, so _PyUnicodeWriter_Dealloc() can be called after finish.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 96c7c58..1a44882 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -13159,18 +13159,21 @@ _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer) { PyObject *str; if (writer->pos == 0) { - Py_XDECREF(writer->buffer); + Py_CLEAR(writer->buffer); _Py_RETURN_UNICODE_EMPTY(); } if (writer->readonly) { - assert(PyUnicode_GET_LENGTH(writer->buffer) == writer->pos); - return writer->buffer; + str = writer->buffer; + writer->buffer = NULL; + assert(PyUnicode_GET_LENGTH(str) == writer->pos); + return str; } if (PyUnicode_GET_LENGTH(writer->buffer) != writer->pos) { PyObject *newbuffer; newbuffer = resize_compact(writer->buffer, writer->pos); if (newbuffer == NULL) { Py_DECREF(writer->buffer); + writer->buffer = NULL; return NULL; } writer->buffer = newbuffer; |