Commit 9e6b4d71 authored by Victor Stinner's avatar Victor Stinner

Issue #18408: _PyUnicodeWriter_Finish() now clears its buffer attribute in all

cases, so _PyUnicodeWriter_Dealloc() can be called after finish.
parent 79799266
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment