Commits

Georg Brandl committed efe706a

#3305: self->stream can be NULL.

  • Participants
  • Parent commits ec97b7a
  • Branches legacy-trunk

Comments (0)

Files changed (2)

File Lib/test/test_multibytecodec.py

 from test import test_multibytecodec_support
 from test.test_support import TESTFN
 import unittest, StringIO, codecs, sys, os
+import _multibytecodec
 
 ALL_CJKENCODINGS = [
 # _codecs_cn
         finally:
             os.unlink(TESTFN)
 
+    def test_init_segfault(self):
+        # bug #3305: this used to segfault
+        self.assertRaises(AttributeError,
+                          _multibytecodec.MultibyteStreamReader, None)
+        self.assertRaises(AttributeError,
+                          _multibytecodec.MultibyteStreamWriter, None)
+
+
 class Test_IncrementalEncoder(unittest.TestCase):
 
     def test_stateless(self):

File Modules/cjkcodecs/multibytecodec.c

 {
 	PyObject_GC_UnTrack(self);
 	ERROR_DECREF(self->errors);
-	Py_DECREF(self->stream);
+	Py_XDECREF(self->stream);
 	Py_TYPE(self)->tp_free(self);
 }
 
 {
 	PyObject_GC_UnTrack(self);
 	ERROR_DECREF(self->errors);
-	Py_DECREF(self->stream);
+	Py_XDECREF(self->stream);
 	Py_TYPE(self)->tp_free(self);
 }