[Python-checkins] r70693 - in python/branches/release30-maint: Lib/test/test_io.py Modules/_fileio.c

antoine.pitrou python-checkins at python.org
Sun Mar 29 21:03:52 CEST 2009


Author: antoine.pitrou
Date: Sun Mar 29 21:03:52 2009
New Revision: 70693

Log:
Merged revisions 70690,70692 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r70690 | antoine.pitrou | 2009-03-29 20:40:13 +0200 (dim., 29 mars 2009) | 3 lines
  
  Fix leak in _fileio.c (patch by Hirokazu Yamamoto)
........
  r70692 | antoine.pitrou | 2009-03-29 20:55:12 +0200 (dim., 29 mars 2009) | 4 lines
  
  Plug another leak, and finally add a test for #1174606 (read() from /dev/zero).
  The leak was the reason my previous attempts at testing failed...
........


Modified:
   python/branches/release30-maint/   (props changed)
   python/branches/release30-maint/Lib/test/test_io.py
   python/branches/release30-maint/Modules/_fileio.c

Modified: python/branches/release30-maint/Lib/test/test_io.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_io.py	(original)
+++ python/branches/release30-maint/Lib/test/test_io.py	Sun Mar 29 21:03:52 2009
@@ -305,6 +305,22 @@
             file = io.open(f.fileno(), "r", closefd=False)
             self.assertEqual(file.buffer.raw.closefd, False)
 
+    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):
+            return     # /dev/zero does not exist
+        if sys.maxsize > 0x7FFFFFFF:
+            return     # test can only run in a 32-bit address space
+        if support.real_max_memuse < support._2G:
+            return     # 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 MemorySeekTestMixin:
 

Modified: python/branches/release30-maint/Modules/_fileio.c
==============================================================================
--- python/branches/release30-maint/Modules/_fileio.c	(original)
+++ python/branches/release30-maint/Modules/_fileio.c	Sun Mar 29 21:03:52 2009
@@ -465,6 +465,7 @@
 			PyErr_SetString(PyExc_OverflowError,
 				"unbounded read returned more bytes "
 				"than a Python string can hold ");
+			Py_DECREF(result);
 			return NULL;
 		}
 
@@ -541,6 +542,7 @@
 	Py_END_ALLOW_THREADS
 
 	if (n < 0) {
+		Py_DECREF(bytes);
 		if (errno == EAGAIN)
 			Py_RETURN_NONE;
 		PyErr_SetFromErrno(PyExc_IOError);


More information about the Python-checkins mailing list