diff -r fb17969ace93 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Tue Jan 15 15:34:08 2013 +0200 +++ b/Objects/unicodeobject.c Tue Jan 15 16:01:19 2013 +0200 @@ -7413,27 +7413,35 @@ goto onError; } - if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) + if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) { + Py_DECREF(x); goto onError; + } PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value); writer.pos++; } else if (PyUnicode_Check(x)) { - if (PyUnicode_READY(x) == -1) + if (PyUnicode_READY(x) == -1) { + Py_DECREF(x); goto onError; + } if (PyUnicode_GET_LENGTH(x) == 1) { Py_UCS4 value = PyUnicode_READ_CHAR(x, 0); if (value == 0xFFFE) goto Undefined; - if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) + if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) { + Py_DECREF(x); goto onError; + } PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value); writer.pos++; } else { writer.overallocate = 1; - if (_PyUnicodeWriter_WriteStr(&writer, x) == -1) + if (_PyUnicodeWriter_WriteStr(&writer, x) == -1) { + Py_DECREF(x); goto onError; + } } } else {