diff -r a4fe32477df6 Lib/test/multibytecodec_support.py --- a/Lib/test/multibytecodec_support.py Wed Jul 15 11:51:22 2015 +1200 +++ b/Lib/test/multibytecodec_support.py Wed Jul 15 22:55:11 2015 -0400 @@ -269,6 +269,7 @@ ostream.write(data) self.assertEqual(ostream.getvalue(), self.tstring[0]) + ostream.reset() class TestBase_Mapping(unittest.TestCase): diff -r a4fe32477df6 Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c Wed Jul 15 11:51:22 2015 +1200 +++ b/Modules/cjkcodecs/multibytecodec.c Wed Jul 15 22:55:11 2015 -0400 @@ -1685,6 +1685,10 @@ { PyObject *pwrt; + if (self->pending == NULL) { + Py_RETURN_NONE; + } + pwrt = multibytecodec_encode(self->codec, &self->state, self->pending, NULL, self->errors, MBENC_FLUSH | MBENC_RESET);