]> granicus.if.org Git - python/commitdiff
Plug another leak, and finally add a test for #1174606 (read() from /dev/zero).
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 29 Mar 2009 18:55:12 +0000 (18:55 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 29 Mar 2009 18:55:12 +0000 (18:55 +0000)
The leak was the reason my previous attempts at testing failed...

Lib/test/test_io.py
Modules/_fileio.c

index 1b80add9039ac045e0f1cfd4b7d1de5cd1eba066..d5be405ef517005c7cf73431805ecbea8972cf90 100644 (file)
@@ -505,6 +505,22 @@ class IOTest(unittest.TestCase):
         with open(support.TESTFN, "rb") as f:
             self.assertEqual(f.read(), b"abcxxx")
 
+    def test_unbounded_file(self):
+        # Issue #1174606: reading from an unbounded stream such as /dev/zero.
+        zero = "/dev/zero"
+        if not os.path.exists(zero):
+            raise unittest.SkipTest("{0} does not exist".format(zero))
+        if sys.maxsize > 0x7FFFFFFF:
+            raise unittest.SkipTest("test can only run in a 32-bit address space")
+        if support.real_max_memuse < support._2G:
+            raise unittest.SkipTest("test requires at least 2GB of memory")
+        with open(zero, "rb", buffering=0) as f:
+            self.assertRaises(OverflowError, f.read)
+        with open(zero, "rb") as f:
+            self.assertRaises(OverflowError, f.read)
+        with open(zero, "r") as f:
+            self.assertRaises(OverflowError, f.read)
+
 class CIOTest(IOTest):
     pass
 
index c3124db33563e6546195359ad8404371fb111646..c0f5c90d13f620fd99a75ea5d95878bf52c66401 100644 (file)
@@ -543,6 +543,7 @@ fileio_readall(PyFileIOObject *self)
                        PyErr_SetString(PyExc_OverflowError,
                                "unbounded read returned more bytes "
                                "than a Python string can hold ");
+                       Py_DECREF(result);
                        return NULL;
                }