[Python-checkins] r81275 - in python/trunk: Lib/test/test_file2k.py Misc/NEWS Objects/fileobject.c

antoine.pitrou python-checkins at python.org
Mon May 17 21:57:00 CEST 2010


Author: antoine.pitrou
Date: Mon May 17 21:56:59 2010
New Revision: 81275

Log:
Issue #7079: Fix a possible crash when closing a file object while using
it from another thread.  Patch by Daniel Stutzbach.



Modified:
   python/trunk/Lib/test/test_file2k.py
   python/trunk/Misc/NEWS
   python/trunk/Objects/fileobject.c

Modified: python/trunk/Lib/test/test_file2k.py
==============================================================================
--- python/trunk/Lib/test/test_file2k.py	(original)
+++ python/trunk/Lib/test/test_file2k.py	Mon May 17 21:56:59 2010
@@ -429,6 +429,7 @@
         self._count_lock = threading.Lock()
         self.close_count = 0
         self.close_success_count = 0
+        self.use_buffering = False
 
     def tearDown(self):
         if self.f:
@@ -443,7 +444,10 @@
         test_support.threading_cleanup(*self._threads)
 
     def _create_file(self):
-        self.f = open(self.filename, "w+")
+        if self.use_buffering:
+            self.f = open(self.filename, "w+", buffering=1024*16)
+        else:
+            self.f = open(self.filename, "w+")
 
     def _close_file(self):
         with self._count_lock:
@@ -530,6 +534,12 @@
             print >> self.f, ''
         self._test_close_open_io(io_func)
 
+    def test_close_open_print_buffered(self):
+        self.use_buffering = True
+        def io_func():
+            print >> self.f, ''
+        self._test_close_open_io(io_func)
+
     def test_close_open_read(self):
         def io_func():
             self.f.read(0)

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Mon May 17 21:56:59 2010
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue #7079: Fix a possible crash when closing a file object while using
+  it from another thread.  Patch by Daniel Stutzbach.
+
 Library
 -------
 

Modified: python/trunk/Objects/fileobject.c
==============================================================================
--- python/trunk/Objects/fileobject.c	(original)
+++ python/trunk/Objects/fileobject.c	Mon May 17 21:56:59 2010
@@ -649,8 +649,10 @@
 file_close(PyFileObject *f)
 {
     PyObject *sts = close_the_file(f);
-    PyMem_Free(f->f_setbuf);
-    f->f_setbuf = NULL;
+    if (sts) {
+        PyMem_Free(f->f_setbuf);
+        f->f_setbuf = NULL;
+    }
     return sts;
 }
 


More information about the Python-checkins mailing list